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.