I'm trying to read a CSV file that looks like this:screenshot of a CSV file
When i read a line that says "Cliente" I want to skip it and read the next line. When i read a line "Itinerarios" I also want to skip it and read all the lines untill the next "Cliente" line. Basically Cliente is a class and Itinerario is a different class that is associated with Cliente, that's why i'm trying to read it that way.
I tried using ss.ignore() in this context but it seems to do nothing: My line is still "Cliente" and the code cant extract the values.
if (fe.good()) {
while (!fe.eof()) {
getline(fe, linea);
stringstream ss;
if (linea != "") {
++total;
if (total > 2) {
if (linea == "Cliente") {
ss << linea;
ss.ignore(20,'\n');
// Starts reading Cliente stuff
getline(ss, dni, ';');
getline(ss, pass, ';');
EDIT: Here's a reduced example:
int main(int argc, char** argv) {
ifstream fe;
string linea;
int total = 0; // Counts lines
string dni;
//Reads the file
fe.open("ClientesItinerarios.csv");
if (fe.good()) {
while (!fe.eof()) {
getline(fe, linea); //Toma una l�nea del fichero
stringstream ss;
if (linea != "") {
++total;
if (total > 2) {
if (linea == "Cliente") {
ss << linea;
ss.ignore(20,'\n');
// Read only the first value to make the example shorter
getline(ss, dni, ';'); //Stores the first part into dni
}
}
}
}
fe.close();
} else {
cerr << "Cannot read file" << endl;
}
return 0;
}
and if it helps heres a screenshot of my debugger when its over getline(ss, dni, ';');