Break loop when key is pressed

I saw some complicated solutions on the web, but am hoping for something simpler. For this application, simple is more important than robust.

I want a console program to continue looping until the user enters a character on the keyboard.
Something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	while ()
	{
		if (!stdin.isEmpty()) // there is no stdin.isEmpty() function in C++
		{
			c = getchar();

			if (c == 'q')
			{
				break;
			}
			if (c == 's')
			{
				printStatus();
			}
		}
		//keep doing loopy task until user hits 'q' or 's'
	}

It's a fast loop, so poling the keyboard or stdin once per loop would be good enough.
I am using MinGW compiler on Windows 7.
I have no multi-threading experience, but can learn it if multi-threading is the simplest way.

Thank you.
If you add Sleep 30 times a second (every "frame"), it will decrease the CPU usage while still appearing sufficiently immediate.

Just a friendly suggestion. :)
Last edited on
The iskeypressed() function implementations I linked do just that.
Thanks Duoas, the example on http://www.cplusplus.com/forum/beginner/5619/#msg25047 is just what I needed.
Topic archived. No new replies allowed.