How to stop, from another thread, std::cin from reading anymore input?
问题 I started two threads, thread t1 is waiting for input via cin . Can I put something like an EOF bit to cin from thread t2 to stop cin from reading? I tried '\n' and ios::eofbit . Both did not work. #include <thread> #include <iostream> #include <string> #include <condition_variable> std::condition_variable cv; void Foo() { std::string sFoo; std::cin >> sFoo; // Do stuff with sFoo } void Bar() { // Do stuff // If a condition is fullfilled I don't need the input in Foo anymore and so I want to