key in function

hey, if i want a user to press a keyboard key(like "k") anytime during a loop so something will happen in addition to everything else in the loop,
how do i do that?

like
1
2
3
4
for(int a=0; a<100; a++){cout<<"somthing";
//if user press K
//cout<<"more something";
}
Last edited on
1
2
3
char ch;
cin>>ch;
if(ch==K){.....}


you can use getch() function;
Last edited on
but if i do that the program will stop waiting for the user input,
i want that while the program is running the user can anytime press "k" to do somthing.
If you want your program to do more than one task at a time, in this case watch for input and process data in the background, then you need more than one thread: http://www.cplusplus.com/reference/multithreading/
Topic archived. No new replies allowed.