I
iaesun
hello,
this post assumes executing a program with file redirection as follows:
program.exe < intput.txt
where input.txt is a text file where there is not necessarily any
whitespace after the last character and the EOF.
i've found some useful posts about detecting EOF when using cin with
file redirection, but they have so far all been analyzing the input
string character by character.
i was wondering if there was a way to do it word by word instead?
for example the follow code snippet:
while (true)
{
cin >> sInput;
if (!sInput.empty())
cout << sInput << endl;
}
prints out each word just fine so long as there is white space after
the last word of the file. if there is no white space, it just keeps
processing the last word over and over in an infinite loop.
now if i was reading in each character, i could test for EOF, but since
i'm not, i'm wondering how to do the same basic thing using the handy
built-in white space reading of cin.
thanks for any help,
jason
this post assumes executing a program with file redirection as follows:
program.exe < intput.txt
where input.txt is a text file where there is not necessarily any
whitespace after the last character and the EOF.
i've found some useful posts about detecting EOF when using cin with
file redirection, but they have so far all been analyzing the input
string character by character.
i was wondering if there was a way to do it word by word instead?
for example the follow code snippet:
while (true)
{
cin >> sInput;
if (!sInput.empty())
cout << sInput << endl;
}
prints out each word just fine so long as there is white space after
the last word of the file. if there is no white space, it just keeps
processing the last word over and over in an infinite loop.
now if i was reading in each character, i could test for EOF, but since
i'm not, i'm wondering how to do the same basic thing using the handy
built-in white space reading of cin.
thanks for any help,
jason