Checking the state of the input stream

closed account (Lv0f92yv)
How do I determine if there is anything (like a newline char) left on the input stream before reading more data from the stream?

I have tried getchar() to take one more character off the stream, but I don't necessarily know that there always will be another char there...

I have also tried cin.clear(), which does not take the newline char off the stream.

Thanks.
i think try something like this:

1
2
3
4
5
6
7
8
char c;
string s; 
do{
       c = cin.peek();
       if (c == '\n')
          {  //not sure what to put here to clear the stream;   }
}while(c != 0);
closed account (Lv0f92yv)
it's the peek that I can use, thanks. I will peek, and if I see what I don't want there, I can use simple getchar();

Thanks......
Topic archived. No new replies allowed.