Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ reading csv file

Tags:

People also ask

How do I read a csv file and display its contents?

Reading CSV Files With csv Reading from a CSV file is done using the reader object. The CSV file is opened as a text file with Python's built-in open() function, which returns a file object.

What is CSV format?

A CSV (comma-separated values) file is a text file that has a specific format which allows data to be saved in a table structured format.


I want to read csv file by using c++ so here is my code

 int main(){
 ifstream classFile("class.csv");
 vector<string> classData;

 while (getline(classFile, line,',')) // there is input overload classfile
        {
            classData.push_back(line);  

        }
}

here is my question : my problem is when it reads the last column of each row (since it is not separated by comma) it reads last column data and first of next row data for example if my data was like

className, classLocation, Professor c++, Library, John

then it reads like className/ classLocation/ Professor c++/ Library / John

is there anyway that I can separate my last column from first of next row? Thank you and sorry that it is confusing


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!