I am basically reading a .txt
file and storing values.
For example:
Student- Mark
Tennis
It will store Mark
into memory as the studentName
.
Now...If it is just
Student-
Tennis
Then it will work fine and produce an error.
However, if the file looks like this
Student-(space)(nothing here)
Tennis
It will store Tennis
into memory as the studentName
, when if fact it should store nothing and produce an error. I use '\n'
character to determine if there is anything after the -
character. This is my code...
istream& operator>> (istream& is, Student& student)
{
is.get(buffer,200,'-');
is.get(ch);
if(is.peek() == '\n')
{
cout << "Nothing there" << endl;
}
is >> ws;
is.getline(student.studentName, 75);
}
I think it is because the is.peek()
is recognizing white space, but then if I try removing white space using is >> ws
, it removes the '\n'
character and still stores Tennis
as the studentName
.
Would really mean a lot if someone could help me solve this problem.