-
white spaces
Just something I dont understand...Lets say you had the follwing data in a file:
cat and mouse
dog and flea
123
fish and bait
bird and worm
456
etc....
if I read in the file as
Code:
while (in.getline (str1, MAX,'\n'))
{
in >> ws;
in.getline( str2, MAX,'\n');
in >> ws >> id >> ws >> ws;
}
it doesnt work. But if I write the last line as
Code:
in >> ws >> id >> ws;
everything is fine. Why is that? There are 2 enter's before the next block of data.
-
One solution is std::getline().
std::string sInput;
while (std::getline(cin, sInput))
{}
Kuphryn
-
I believe ws takes in all the whitespaces before the next character/until EOF, so therefore, after the first ws executes, there's nothing left for teh second ws to get rid of...