Linux で gcc4.8.1 を使用してコンパイルしたサンプル コードと結果を次に示します。
//content of test.txt
1 2 3 4 5
int main()
{
fstream fs ("test.txt", std::fstream::in );
istream_iterator<string> is1(fs),eof1;
istream_iterator<string> is2(fs),eof2;
while(is1!=eof1){
cout<<"is1:"<<*is1++<<endl;
}
while(is2!=eof2){
cout<<"is2:"<<*is2++<<endl;
}
return 0;
}
//result unexpected
$./m
is1:1
is1:3
is1:4
is1:5
is2:2
結果から、複数の入力 iterator を使用すると、予期しない結果になることがわかります。なぜこれが起こるのか、誰かが私にヒントを与えることができますか?