2

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?

4

2 に答える 2

2

消費されないストリームの部分は変更されません。したがって、以降の呼び出しgetlineは空の行を返します。

正確なファイルの内容がわからない場合は、を試してくださいcat -A filename

于 2012-04-28T13:34:26.533 に答える
0

Try it out. You can do

ifstream fin(filename);
string x;
fin >> x;
cout<<x<<"foo";

you will notice it ;)

于 2012-04-28T13:27:38.577 に答える