how to read a comma delimited file in C ++

1

My question is this, I have an integer text file which I need to get every complete number that is separated by commas. I know that with spaces the compiler knows that they are different things, but how can I do it if they are commas?

    
asked by Bishuu 05.11.2017 в 03:38
source

1 answer

1

You can use std::getline and std::stringstream :

std::string linea;
while(std::getline(fichero,linea))
{
    std::stringstream   stream(linea);
    std::string         valor;

    std::cout << "Contenido de la linea:\n";
    while(std::getline(stream,valor,','))
    {
        std::cout << "valor leido: " << valor << '\n';
    }
    std::cout << "Fin de la linea\n";
}

For future questions please, put code that shows where you are stalling.

    
answered by 05.11.2017 в 19:51