Read an Excel file .csv (C ++)

1

I am trying to read data from an Excel file saved in csv format, my Excel file has six rows and 49 columns, as you can see in the photo:

I want to read data from that file, I'm doing this code:

ifstream inFile;
inFile.open("datacsvformatdelimitadoporcomas.csv");
string nombre2="factura";
string b= ".xml";
string suma= nombre2+ b;
ofstream fout(suma.c_str());
vector<string> cabeceras;

string campo;
string line;
while(getline(inFile, line)){//coges linea por linea
    istringstream s(line);
    string field;
    while (getline(line,campo,';')) {
        cabeceras.push_back(campo);
    }
}
for(int i=0;i<cabeceras.size();i++){
    cout<<cabeceras[i]<<endl;
}

However, I get errors when compiling:

The error is this:

no matching function for call to 'getline(std::string&, std::string&, char)'

Referring to this first line:

while (getline(line,campo,';')) 

I have taken away the; but in the same way I still get the error.

    
asked by AER 15.04.2018 в 01:49
source

1 answer

1

The std::getline function expects to receive a stream of input data, you are passing a string of characters, hence the error:

no matching function for call to 'getline(std::string&, std::string&, char)'

That is basically telling you that there is no version of getline that accepts two std::string as the first and second parameters followed by a char as the third parameter. Surely you wanted to write this:

istringstream s(line);
string field;
while (getline(s, field, ';'))
    
answered by 16.04.2018 / 09:43
source