Is this possible?



1
2
3
4
5
6
string str;
cin >> str;
check(str);
//wait this aint right user enterd input in different format
//lets put it back into the cin stream because he probably meant to use it later
str >> cin; 


Please tell me how to do it.
1
2
3
4
5
string str;

do {
    cin >> str;
}while(str != "quit");

something like this? :P
also, to make sure, you can convert the str variable into all lower case letters.
I guess you can do that with istream::putback.
I don't see how that would be needed though.. One way or another you will end up reading that string again, so why not just process it as you have it. If you need >>, you can use a stringstream. If your program is so chaotic, that you can't know in what order code is executed, you might want to consider restructuring it.
I don't know for sure that it would be needed, but its intuitive that something like this would be possible.

A user enters an input, and then goes on to continue typing into the stream expecting it to be stored for when needed, for faster program execution. (The user is experienced with the console app and knows what is coming next). But forwhatever reason the first input is invalid, but the remaining input is correct. Instead of just junking everything, just junk the bad parts, and put the rest back into the stream.

And I was reading about putback. It seems putback can only be used to putback the last character read, and nothing more. So that doesn't really work.
putback can work for strings.

I don't know whether streams were intended to be used like this. Streams are for moving data, not storing it. If you need to use a stream like this, you can easily write a wrapper class, which would read either from cin or from some vector of its own.
Topic archived. No new replies allowed.