Hello!
So my problem is this, my program has a getline(cin, stringvar) within a while(true) loop and I want to do other tasks if getline doesn't have any input to read from cin, instead of just sitting there and blocking.
Any ideas?
my first idea was to just run 2 threads, one repeating 'my_other_task()' over and over, and the other repeating getline(..), but I think this solution would be better in my case, if I could figure out how to solve this.Code:void my_other_task() {cout << "I am so busy" << endl;} bool is_there_input() {//What goes here?} int main() {while(true) {string user_input; if(is_there_input())getline(cin,user_input);elsemy_other_task();}}
Any ideas on the correct way to do this?
(my initial guess was that since cin is an 'istream', I could use peek(), but it doesn't seem to work...)



1Likes
LinkBack URL
About LinkBacks


