I want to read text from text file into my c++ code. Here is my code:-
f.open(input);
if (f)
{
while(!f.eof())
{
LinkedList obj;
string c, d, l;
f>>c>>d>>l;
nodes.push_back(c);
nodes.push_back(d);
vector<string> temp;
temp.push_back(c);
temp.push_back(d);
temp.push_back(l);
vecNodes.push_back(temp);
}
}
My text file is below:
a b c
a c
d e
e
g h a
My question is how can I read one line at one time. When my code read the second line it go also read the first character of third line Which is wrong. I know I can put delimiter at the end of each line which might work. Is there any other way to do this?