I have a member friend function that receives an istream and reads values from it into private attributes of the object:
1 2 3 4 5 6 7
istream &operator>>(istream &is, Object1 &p) {
is >> p.int1;
is >> p.int2;
getline(is, p.string1);
return is;
}
the file looks like this:
1 2 3
3 5 this is a
4 10 string to
5 20 read and such
If I wanted to read in the first line, I would want p.int1 = 3, p.int2 = 5, and p.string1 = "this is a".
However, I instead get p.string1 = " this is a". I don't want the space in front, but I cannot figure out how to get rid of it. What would be an efficient and readable way to read in the values?