0

Hello,
I'm learning C++ and i want to know how i can develop a program that reads a file like a database, but the program don't know how many lines or columns the file have, and the file is like this:

"Name Test" "1901" "email@test.com"
"John Google" "6673" "john@test.com"

And how i can remove the quotes automatically, remember that this is a test file, the program have to read more lines or not and the program don't know how many lines and columns are, this is my difficult.

Thanks,
Nathan Paulino Campos

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Nathan Campos
0

Suggest you use getline() to read the entire line, then use stringstream object to split it into words.

std::string line;
ifstream in("file.txt");
while( getline( in, line) )
{
     std::string word;
    stringstream str(line);
    while( str >> word )
    {
       // now do something with this word
    }
    
}

As for the quotes -- you will have to parse the word and strip them out if they exist.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.