I need to read from a file and then break the line into 3 strings.
The format is:
A first_The Secod_Third (three underscores)
It’s homework, and they suggest us using getline and ignore.
so I have:
main()
ifstream inf("file.txt")
while(inf)
{inf >> class1;
cout << class1;
}
class THECLASS
{string a, b, c;
public:
friend void operator>>(ifstream &inf, THECLASS &class1)
{getline(inf, class1.a, '_');
inf.ignore();
inf.ignore();
[if I put getline class1.b, the whole line will go into it, overwriting .a]
}
and in operator<<, I have
os << class1.a << class1.b;
return os;
But all I get when I cout << class1 are all three fields of input file without _, each on a new line.
When I tried using get() function, compiler won’t recognize it even though I declared fstream.
What is the general algorithm of doing it?
Hope this can help u.