Reputation: 492
As I understand the extraction operator>> is delimitered by whitespace. Does the extraction operator remove the delimiter from the stream? E.g., say I have the file
6
Foo
Bar
and the code
ifstream fin(filename);
int x;
fin >> x;
does the filestream still contain the newline character that followed the 6 (potentially messing up subsequent getline statements)? Or was this removed in the extraction process?
Upvotes: 2
Views: 832
Reputation: 10927
The part of the stream not consumed remains unchanged. So a subsequent call to getline
will return an empty line.
If you are unsure about the exact file content, try cat -A filename
.
Upvotes: 2
Reputation: 825
Try it out. You can do
ifstream fin(filename);
string x;
fin >> x;
cout<<x<<"foo";
you will notice it ;)
Upvotes: 0