Question

Read - Write CSV Files in C++

Asked by: BabyhueyHN

I have a problem trying to get CSV files to work with my program. It works fine with tab delimited but not with csv. Anyone know of a way to read in csv files and write back out to them.  The values separarted can be various lengths. Thanks

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-06-17 at 15:28:19ID20651518
Tags

csv

,

file

,

read

Topic

C++ Programming Language

Participating Experts
4
Points
400
Comments
30

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. remove tab-delims from csv file
    i'm looking to remove tab delim squares from a csv imported into access. would prefer to do within if that's not going to cause performance problems (largeish csv files + access goes char by char). however, suggestions for other options welcome. bonus for code that returns...
  2. Import tab delimited or CSV file
    how do I import tab delimited or CSV files data to MS Access database through JAVA? Thanks in Advance
  3. Checking the delimiter in a csv file
    Hello Experts, I have some csv files , in some csv files the values are separated by ' ,' and in some other csv files the values are separated by ' ; ' . I need a java code to check whether the csv file is separated by , or ; and if the csv file is separated by ' ; ' then i s...
  4. Crating a Tab Delimited csv file??
    I'm a bit confused. I have a tab delimited CSV file right in front of me. It opens just fine in Excel. I'm trying to recreate this with ColdFusion, but can't get Excel to open the file properly. (On a side note, I can successfully create comma delimited CSV files - but th...
  5. Windows script to convert a Fixed Length Text file to CSV f…
    I am looking for a way to write a dynamic Windows Script to convert a Fixed Length Text File to CSV format...
  6. Export semicolon ; delimited csv file
    I need to save as a .csv but have the delimiter be a ; instead of the default comma. How do I do this?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ExceterPosted on 2003-06-17 at 16:51:38ID: 8745149

You can use getline to read in each element. For example,

ifstream in("myfile.csv");
char val[100];

while( in )
{
    in.getline( val, 100, ',' );
    cout << val << endl;
}

in.close();

Exceter

 

by: ExceterPosted on 2003-06-17 at 17:01:57ID: 8745194

However, this is a better way,

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

int main()
{
      ifstream in("test.csv");
      vector < vector <string> > data;
      string element, delimiters = ",";
      int row = 0;
      char ch;

      data.push_back( vector <string>() );

      while( in.read( (char*)&ch, 1 ) )
      {
            if( ch == '\n' || ch == '\r' )
            {
                  data.push_back( vector <string>() );
                  row++;
            }
            else if( delimiters.find_first_of(ch) == delimiters.npos )
            {
                  element += ch;
            }
            else
            {
                  data[row].push_back( element );
                  element = "";
            }
      }

      in.close();

      for( unsigned int x = 0; x < data.size(); x++ )
      {
            for( unsigned int y = 0; y < data[x].size(); y++ )
            {
                  cout << data[x][y] << ",";
            }
            cout << endl;
      }

      return 0;
}

Exceter

 

by: ExceterPosted on 2003-06-17 at 18:00:46ID: 8745425

Actually, that had a bug in it, try this instead,

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

int main()
{
      ifstream in("test.csv");
      vector < vector <string> > data;
      string element, delimiters = ",\n\r";
      int row = 0;
      char ch;

      data.push_back( vector <string>() );

      while( in.read( (char*)&ch, 1 ) )
      {

            if( delimiters.find_first_of(ch) == delimiters.npos )
            {
                  element += ch;
            }
            else
            {
                  if( ch != '\r' )
                  {
                        data[row].push_back( element );
                        element = "";

                        if( ch == '\n' )
                        {
                              data.push_back( vector <string>() );
                              row++;
                        }
                  }
            }
      }

      if( element.size() > 0 )
            data[row].push_back( element );

      in.close();

      for( unsigned int x = 0; x < data.size(); x++ )
      {
            for( unsigned int y = 0; y < data[x].size(); y++ )
            {
                  cout << data[x][y] << ",";
            }
            cout << endl;
      }

      return 0;
}

Exceter

 

by: martynjpearsonPosted on 2003-06-18 at 00:48:37ID: 8747130

Is the problem happening because some of the data contains commas? If it does, then you will need to make sure that for those items at least, they are "contained" in some way, say between double quotes. Then, you'll need to adapt your algorithm to correctly read in the whole item, ignoring any commas that it contains. The other way you could do it is to "escape" the commas that are part of the data, in much the same way as string literals escape quote characters.

Hope this helps!

 

by: ExceterPosted on 2003-06-18 at 08:09:39ID: 8749897

BabyhueyHN?

 

by: BabyhueyHNPosted on 2003-06-19 at 13:54:35ID: 8761549

Thanks for the code, It worked great. I didn't understand some of it , but it worked.

 

by: ExceterPosted on 2003-06-19 at 15:04:46ID: 8762042

You are most welcome. Indicate the sections you do not understand and I'll do my best to explain them.

Cheers!
Exceter

 

by: BabyhueyHNPosted on 2003-06-23 at 10:31:37ID: 8783196

Exceter,
      You code works to display the data in the fields between the delimiters. However, I need to be able to manipulate the data in those fields in order to combine parts of strings in different fields. Should I post this as a new question or can you tell me how I should do it. I have tried strncpy and strncat to no avail. Thanks, Don

 

by: ExceterPosted on 2003-06-23 at 11:11:20ID: 8783465

>> I need to be able to manipulate the data in those fields in order to combine parts of strings in different fields.

That's no problem. The fields are read into std::string. Therefore, all you have to do to extract/insert data into the given field is to access it via operator[] and use the assignment operator to insert/remove data. For example,

string s = data[0][0]; // Place the first field from the first row into s
data[0][0] = "Testing..."; // Set the first field to the string literal, "Testing..."

You can then write the vector out to file in roughly the same manner you printed it to the screen. Alternatively, you can use char arrays if you want, but I wouldn't. For example,

char s[25];
strcpy( s, data[0][0].c_str() ); // Copy the first field into s

...

data[0][0] = s; // Copy the value back into the vector

Exceter

 

by: ExceterPosted on 2003-06-23 at 13:11:38ID: 8784292

Here, I took a few minutes and threw this together(who knows; I may find it usefull in the future).

-- csv.h --

#ifndef CSV_H
#define CSV_H

#include <iomanip>
using std::endl;

#include <fstream>
using std::ifstream;
using std::ofstream;

#include <string>
using std::string;

#include <vector>
using std::vector;

class csv
{
      friend bool operator==( const csv &, const csv & );
      friend bool operator!=( const csv &, const csv & );

      public:
            csv();
            csv( char* );
            void read( char* );
            void write( char* );
            string getfield( int, int );
            void setfield( int, int, string );
            const csv &operator=( const csv & );
            int rows, cols;

      private:
            vector < vector <string> > data;
};

csv::csv()
{
      rows = cols = 0;
      data.push_back( vector <string>() );
}

csv::csv( char* fname )
{
      read( fname );
}

const csv &csv::operator=( const csv &n )
{
      rows = n.rows;
      cols = n.cols;
      data = n.data;

      return *this;
}

void csv::read( char* fname )
{
      ifstream in( fname );
      string element, delimiters = ",\n\r";
      char ch;

      rows = cols = 0;
      data.clear();

      data.push_back( vector <string>() );

      while( in.read( (char*)&ch, 1 ) )
      {
            if( delimiters.find_first_of(ch) == delimiters.npos )
                  element += ch;

            else
            {
                  if( ch != '\r' )
                  {
                        data[rows].push_back( element );
                        element = "";
                        if( ch == '\n' )
                        {
                              data.push_back( vector <string>() );
                              rows++;
                        }
                  }
            }
      }

      in.close();
      data[rows].push_back( element );
      cols = data[0].size();
      rows = data.size();
}

void csv::write( char* fname )
{
      ofstream out( fname );

      for( int x = 0; x < rows; x++ )
      {
            for( int y = 0; y < cols; y++ )
            {
                  out << data[x][y];
                  if( y != cols - 1 )
                        out << ",";
            }
            out << endl;
      }

      out.close();
}

string csv::getfield( int x, int y )
{
      return data[x][y];
}

void csv::setfield( int x, int y, string val )
{
      data[x][y] = val;
}

bool operator==( const csv &d1, const csv &d2 )
{
      return d1 == d2;
}

bool operator!=( const csv &d1, const csv &d2 )
{
      return d1 != d2;
}

#endif

-- test.cpp --

#include <iostream>
#include <iomanip>
#include "csv.h"

using namespace std;

int main()
{
      csv mycsv("test.csv");
      mycsv.setfield(0,0,"testing");
      mycsv.write("test1.csv");

      return 0;
}

Hopefully, this should make dealing with the csv file much easier.

Exceter

 

by: ExceterPosted on 2003-06-23 at 13:13:11ID: 8784309

>> csv::csv()
>> {
>>     rows = cols = 0;
>>     data.push_back( vector <string>() );
>> }

This would cause problems, that should have been,

csv::csv()
{
    rows = cols = 0;
}

Exceter

 

by: BabyhueyHNPosted on 2003-06-25 at 13:11:07ID: 8800522

Exceter,

     I am still having problems getting the program to allow me to manipulate the data. Can I send you the file, to show you the problem. Thanks

 

by: ExceterPosted on 2003-06-25 at 15:11:08ID: 8801336

Post the code and the file, if necessary, and I'll be glad to help.

 

by: BabyhueyHNPosted on 2003-06-25 at 18:04:24ID: 8801953

I'm trying to make TestCsv.cpp (works with idsNew.csv datafile) program to manipulate characters in fields one and
two i.e. break the fields and combine 1 charcater from field 1, 3 characters from field2 and last 4 characters of field 3.
The program codeWstring.cpp(idsNew.txt data file) does exactly what I need with the fields,  but it does not read a comma-delimited file.  Thanks for all your help. Thanks, Don
 
_____________________________________________

// codeWstring.cpp  -

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include<iomanip>
using namespace std;
#include<ctype.h>      //can only find ctype.h
//using std::setiosflags;
//using std::resetiosflags;
//void idText(idCharPart, fName, lName);

void main()
{
    ifstream in("idsNew.csv");
      ofstream outFileCsv("ids.csv");
      ofstream outTxt("ids.txt");
    vector < vector <string> > data;
    string element, delimiters = ",\n\r";
//      char string1[5], string2[5], idCharPart[5] = {""} ;
      int ssn;
      string campus;
      int uniqueId=1000001, tempId;

    int row = 0;
    char ch;

    data.push_back( vector <string>() );

    while( in.read( (char*)&ch, 1 ) )
    {

         if( delimiters.find_first_of(ch) == delimiters.npos )
         {
              element += ch;
         }
         else
         {
              if( ch != '\r' )
              {
                   data[row].push_back( element );
                   element = "";

                   if( ch == '\n' )
                   {
                        data.push_back( vector <string>() );
                        row++;
                   }
              }
         }

    }

    if( element.size() > 0 )
         data[row].push_back( element );
            
    in.close();

    for( unsigned int x = 1; x < data.size(); ++x )
            
    {        
            for( unsigned int y = 0; y < data[x].size(); y++ )
         {
                    outFileCsv<< data[x][y] << ",";
                    cout<<data[x][y] << ",";

                    typedef char string[20];          // I need to manipulate my strings
                    string fName, lName, idCharPart;  //  i.e. to break and combine them,  
                    if (y == 0)                       // but no metter what I try it does not work :(
                    {
                        fName = data[x][y];
                    }
                    if (y == 1)
                    {
                        lName = data[x][y];
                    }
                  strncpy(idCharPart, fName, 1);
                  idCharPart[1] = '\0';
            
                  strncat(idCharPart, lName,3);

                  if(strlen(idCharPart) < 4)
                        strcat(idCharPart, "_");

                  idCharPart[0] = tolower(idCharPart[0]);
                  idCharPart[1] = tolower(idCharPart[1]);
                  idCharPart[4] = '\0';
//                    idText(idCharPart, string1, string2);
            }
            
            tempId = uniqueId % 10000;

            outFileCsv<<idCharPart<<setw(4)<<setfill('0')<<tempId<<","<<uniqueId<endl;
            cout<<idCharPart<<setw(4)<<setfill('0')<<tempId<<","<<uniqueId<<endl;

            uniqueId++;
    }
}
/*
void idText(string idCharPart, string fName, string lName)
{  
            char filler[2] = {"_"};

            strncpy(idCharPart, fName, 1);
            idCharPart[1] = '\0';
            
            strncat(idCharPart, lName,3);

            if(strlen(idCharPart) < 4)
                  strcat(idCharPart, filler);

            idCharPart[0] = tolower(idCharPart[0]);
            idCharPart[1] = tolower(idCharPart[1]);
            idCharPart[4] = '\0';
}
*/
__________________________________________________

//  TestPrWorks.cpp

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
#include<ctype.h>
void idText(char idCharPart[], char fName[], char lName[]);

int main()
{
      ifstream inFile("idsNew.txt");
      ofstream outFile("idsOut.txt");
      ofstream outFileCsv("idsOutTemp.csv");
//      char fName[15], lName[18], idCharPart[5] = {""}, major[5], filler[2] = {"_"};
      char fName[15], lName[18], idCharPart[5] = {""}, major[5];  //if with fumction

      char ssn[10], campus[5];
      int tempId = 1, uniqueID = 1000001;

      outFileCsv<<"f_name"<<","<<"l_name"<<","<<"SSN"<<","<<"campus"<<","<<"id"<<endl;

      while(inFile)
      {
            inFile>>fName>>lName>>ssn>>campus>>major;  
            idText(idCharPart, fName, lName);

             tempId = uniqueID % 10000;

            outFileCsv<<fName<<","<<lName<<","<<ssn<<","<<campus<<","
                        <<idCharPart<<setw(4)<<setfill('0')<<tempId<<endl;
            cout<<fName<<","<<lName<<","<<ssn<<","<<campus<<","
                  <<idCharPart<<setw(4)<<setfill('0')<<tempId<<endl;

            uniqueID = uniqueID+1;
      }
}

void idText(char idCharPart[], char fName[], char lName[])
{  
            char filler[2] = {"_"};

            strncpy(idCharPart, fName, 1);
            idCharPart[1] = '\0';
            
            strncat(idCharPart, lName,3);

            if(strlen(idCharPart) < 4)
                  strcat(idCharPart, filler);

            idCharPart[0] = tolower(idCharPart[0]);
            idCharPart[1] = tolower(idCharPart[1]);
            idCharPart[4] = '\0';
}

_____________________________________________________

idsNew.csv  File

John,Dow,123456789,1,BUAD
Henry,Tester,987654321,1,DPRP
Crapoita,O'Conner,123456788,1,LA
Julie,Abdul,123456787,1      BSOC
Muhammad,Abb-Alkehm,546465654,1,DPRN
Daniel,Aba,323156544,1,EGR
Jen,Yu,789654213,1,DPRN
_____________________________________________________
idsNew.txt File

John Dow 123456789 1 BUAD
Henry Tester 987654321 1 DPRP
Crapoita OConner 123456788 1 LA
Julie Abdul 123456787 1 BSOC
Muhammad AbbAlkehm 546465654 1 DPRN
Daniel Aba 323156544,1,EGR
Jen Yu 789654213 1 DPRN


*I had to take all the spaces ' . and - out of the names manually to get it to work because I cannot use those in the creation of the names and I can't figure out how to automatically get rid of them.

 

by: ExceterPosted on 2003-06-25 at 19:37:27ID: 8802316

What should the output look like?

 

by: BabyhueyHNPosted on 2003-06-26 at 09:31:24ID: 8806627

The output should look like:
Fname,Lname,SSN,Campus,Code,UID,UName
John,Dow,123456789,1,BUAD,1000001,jdow0001

The biggest problem is that in the CSV file we have to take the - / spaces / ' and .  out of the csv file becasue we cannot maniputate the data in the fields.

CSV File Example  John,Yu Pan,123456789,1,BUAD
Output should be John,Yu Pan,123456789,1,BUAD,1000001,jyup0001

CSV File Example  John,O'Conner,987654321,1,DPRS
Output should be John,O'Conner,987654321,1,DPRS,1000002,joco0002

CSV File Example  John,Hu,542136555,1,ECO
Output should be John,Hu,542136555,1,ECO,1000003,jhu_0003


We cannot preserve the name John,Yu Pan we must change it to John,YuPan manually for the program to work. The same is true for last names of o'Conner etc. If a last name has only 2 characters then we assign an _ for the third character.

I would like to assign data[x][y] to an array of chars in order to break data [x][y] and create a new field with the elements of data [x][y]. I need to be able to manipulate the data and have it ignore certain characters (',.,-, spaces) etc... So I can create the correct ID's . Thanks, Don

 

by: BabyhueyHNPosted on 2003-06-26 at 10:22:56ID: 8806991

dynamic string objects that can be freely exchanged with standard char* types (so there is no need to change function calls nor the implementation when you change from char* to String (and vice versa)).  I think thats what I need.

 

by: ExceterPosted on 2003-06-26 at 20:01:46ID: 8810337

>> I would like to assign data[x][y] to an array of chars in order to break data [x][y] and create a new field with the elements
>> of data [x][y].

You can do that by saying,

char st[50];
strcpy( st, data[x][y].c_str() );

Well, you can strip out the unwanted characters with the following function,

string removechars( string st, string delim )
{
    string result = "";

    for( unsigned int x = 0; x < st.length(); x++ )
    {
         if( delim.find_first_of( st[x] ) == delim.npos )
             result += st[x];
    }
    return result;
}

All you have to do is pass it the string which you want the characters removed from and a second string containing the characters to be removed. For example,

string st = ( "This i's a test...", " '." );
cout << st << endl;

-- output --
Thisisatest

>> dynamic string objects that can be freely exchanged with standard char* types (so there is no need to change function
>> calls nor the implementation when you change from char* to String (and vice versa)).

Go with std::string. It can be exchanged freely with char* types. When you want to call a function that accepts a char* with text contained in an instance of std::string all you have to say is,

myfunc( mystring.c_str() ); // c_str() returns a char* pointer to the text within the string object

I'll get back to you on the other stuff as soon as I can.

Note: That class I posted has a bug or two. If I can find the time to debug it, I'll post a new version.

Exceter

 

by: neelePosted on 2003-09-29 at 18:21:51ID: 9456087

hello  Exceter

i try your code for CSV, am having error with
friend bool operator==( const csv &, const csv & );
friend bool operator!=( const csv &, const csv & );

if i comment them away it is fine. Actually can u tell me
what is the main purpose for the operator methods??..
u created..

 

by: ExceterPosted on 2003-09-29 at 19:07:38ID: 9456221


Hi neele,

I created the != and == operators so you could compare two csv files if you wanted. You'd load a csv file into one instance of the class and another csv file into another instance of the class. You could then determine whether they were equal or not by saying,

if( file1 == file2 ) // If the csv files are equal, do whatever
{
    // etc...
}

if( file1 != file2 ) // If the csv files are not equal, do whatever
{
    // etc...
}

Exceter

 

by: neelePosted on 2003-09-29 at 20:52:17ID: 9456526

Oh i see :) for that purpose..
But i am having compile error, only commenting away this 2 line will be ok
friend bool operator==( const csv &, const csv & );
friend bool operator!=( const csv &, const csv & );

so how to edit it so there isn't any compilation error.
Thanks exceter.

 

by: ExceterPosted on 2003-09-29 at 21:54:28ID: 9456739

Could you post the offending code and the errors?

 

by: neelePosted on 2003-09-29 at 22:16:34ID: 9456820

warning C4786: 'std::vector<std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >,std::allocator<s
td::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > > >' : identifier was truncated to '255' characters in the debug information

error C2593: 'operator ==' is ambiguous
error C2593: 'operator !=' is ambiguous

That the error and warning messages...
By the way when i build (after commenting away the error lines)
I will have abt 30 warnings..due to the std::vector..

Any suggestions? or y i having those warning.
Thanks a lot !

 

by: ExceterPosted on 2003-09-30 at 06:54:41ID: 9459299

Could you post the code that is giving you the errors?

 

by: ExceterPosted on 2003-09-30 at 07:06:36ID: 9459371

Have you tried compiling your code in release mode?

 

by: neelePosted on 2003-09-30 at 18:46:57ID: 9463213

Hello Exceter

I just tried to compile in release mode ..previously i using debug mode.
Yeah..it works..no more warnings...:D thanks !

But can i ask what the diff to compile in debug/release mode?
actually i am fairly new..in c++

and i know why i having the 'operator !=' is ambiguous,
as i try to print out some values using cout
thus i added using namespace std; causing the error.
Any idea how to allow me to use cout, getline IF i really need it together
with your code? so it won't have confilcts? i did try append std :: getline..
is that the best way out? Thanks once again

 

by: neelePosted on 2003-10-06 at 02:55:28ID: 9497248

Hello Exceter ...

need some help..i am compiling your code on MAC..
but it seem that MAC cannot recognise \r\n??
as the output is only "testing" in the file output ;c

can u advise ...thanks..

 

by: ExceterPosted on 2003-10-13 at 05:43:20ID: 9539696

I never use MACs.

>> but it seem that MAC cannot recognise \r\n??

Sorry, that is OS specific code. Windows use a CR/LF pair to indicate the end of a line. I'm not sure what MAC uses. Have you tried a plain old '\n' ?

Exceter

 

by: neelePosted on 2003-10-13 at 07:00:41ID: 9540221

Hello.. Exceter

it works already now. Guess is OK already is my issue..;c
din place the file at the correct directory of mac..as i
am new..to tat as well ;o
But ya mac n win have different \r\n ..
i also unsure correct or not, yet to fully test the code..if there
is anything i will post again Thanks !

 

by: 0av067Posted on 2009-01-14 at 18:03:27ID: 23379961

When I use the write function i'm getting an assertion error ("vector subscript out of range").  I can't figure out how to fix this.  I'm using Visual C++ Express.  Can anyone please help?

It seems to come from line 779 of the vector template and I don't think it would be prudent for me to go in and edit that line in the standard template.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...