this is my first question here, so please feel free to give any advice about my style.
I'm new to programming in C++. I'm using Windows. My problem is the following: I need a way to wait for an input for a limited time, so I can't use cin
or _getch()
or similar functions.
So my question is: is it possible to force the action of taking an input? I mean, even if the user typed not a single character, to retrieve an empty input of any kind (I guess an empty char array). That way I could do something like this:
int main(){
cout << "Enter a 0 when you wish to stop the program..." << endl;
int stop = 0;
char buffer[20];
while(stop==0){
//main task of the loop
//force to store the input inside buffer[], even if no input
if(buffer=="0"){
stop = 1;
}
}
By the way, the questions that I read related with this topic are a little bit old. If there is a simpler way to wait a certain amount of time for an user input, forget about that code and forcing the entry of data. Thank you very much for your time and forgive my inexperience.