checking if cin still have more strings in input stream

Hello, Im writing a program on a Unix machine which accepts input using only "cin >>", the inputs look something like this:

hello world test out

Once I have read "hello" using "cin >>" I need to check if there are more strings (such as "world", "test", and "out", excluding spaces) within this input stream without having to read-in the stream, is there a method of some sort to do this?

or, to rephrase the above question, is there a way to check if the input stream is empty (ignoring spaces) after reading in some of the strings?
Last edited on
Yes.

A stream has a state and can be good, bad or failed I think. There is a convenient overloaded that allows you to check the state easily.

The following code fragment reads all words from a stream.
1
2
3
    std::string str;
    while(std::cin)
        std::cin >> str;


The syntax of C++ allows that to be compressed to:
1
2
3
    std::string str;
    while(std::cin >> str)
        ;
Topic archived. No new replies allowed.