Check for input from console in C++
-
Hi, I have a loop in a C++ program which is constantly checking for input from a network source, but I also want to check if the user has entered something into the console - such as a command to stop the program. Obviously I cannot use just standard cin << strCommand;, since that would block until something is entered. Is there any way for me to check if the console has received input? Regards, Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
-
Hi, I have a loop in a C++ program which is constantly checking for input from a network source, but I also want to check if the user has entered something into the console - such as a command to stop the program. Obviously I cannot use just standard cin << strCommand;, since that would block until something is entered. Is there any way for me to check if the console has received input? Regards, Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
-
you can use the
_kbhit()
function. This function returns a nonzero value if a key has been pressed.