C
Chris Mantoulidis
Let's say I have this:
std::string s1;
std::cin >> s1;
This will read s1 from cin until it finds a space (or a newline,
whichever comes first).
Okay this works. But when I want to continue reading it reads what's
left over in the cin, and well that's logical.
At first I thought that std::cin.clear() would sort that out, but it
didn't... So what does clear() do anyway, if not clear all cin data?
I looked it some places and saw that ignore is what I needed...
std::ignore(1000, '\n'); (or something bigger than 1000 characters).
However I don't like this very much... What if there were 10^100 other
characters in the input before the new line (this isn't possible I
guess but I'm just trying to explain why I don't like that way).
And in some examples I see the use of clear() but still I can't
understand what it does.
Thanks in advance,
cmad
std::string s1;
std::cin >> s1;
This will read s1 from cin until it finds a space (or a newline,
whichever comes first).
Okay this works. But when I want to continue reading it reads what's
left over in the cin, and well that's logical.
At first I thought that std::cin.clear() would sort that out, but it
didn't... So what does clear() do anyway, if not clear all cin data?
I looked it some places and saw that ignore is what I needed...
std::ignore(1000, '\n'); (or something bigger than 1000 characters).
However I don't like this very much... What if there were 10^100 other
characters in the input before the new line (this isn't possible I
guess but I'm just trying to explain why I don't like that way).
And in some examples I see the use of clear() but still I can't
understand what it does.
Thanks in advance,
cmad