How to make getline () read only what the user typed into the console after the getline () execution?

Hey.
I've got a LOT of problems today... I hope this one is the last one.
In SOME tests of my new program when I must type in some text using getline () it doesn't let me type in anything and it looks like it sensed the enter (/n) form nowhere (well... actually these SOME tests include me typing enter into the console but deffinitely before the getline () execution). Is there a way to make sure getline () WON'T read anything before it's execution? I'm asking this because it's causing actually many more problems than I mentioned above.

Maurycy5
Last edited on
Is there a way to make sure getline () WON'T read anything before it's execution?
The only generic way to do that is to consule ALL input from previous executions.

If you are only interested in skipping stray newline symbol which might be left unconsumed by previous formatted input: http://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction
TL;DR: std::getline(std::cin >> std::ws, some_string);
Topic archived. No new replies allowed.