Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read a line in C++ in a certain pattern and store it in a string?

Tags:

c++

I want to read each line of txt file which resembles something like this

1190/2132 123/23123 45

I want to read the whole line and then store them in three separate strings for future use to build a tree . I am using fgets right now , but getting errors regarding putting it into a string . How should i do it ?

like image 996
Hick Avatar asked Sep 21 '10 21:09

Hick


Video Answer


1 Answers

Try this:

std::string  line;

while(std::getline(file, line))
{
    std::stringstream  linestream(line);

    std::string word1, word2, word3;
    line >> word1 >> word2 >> word3;

    // Store words
}
like image 189
Martin York Avatar answered Oct 01 '22 18:10

Martin York