I've been having an issue recently with std::cin
where when I try to use it in conjunction with std::this_thread::sleep_for()
, it starts to get an input when it hasn't even been called yet.
Here's the code I've been using:
#include <iostream>
#include <chrono>
#include <thread>
#include <string>
using std::string
using namespace std::this_thread
using namespace std::chrono
int main(){
string a;
sleep_for(seconds(3)); //start typing around now
std::cin >> a; //the text typed during the sleep_for() shows up now
return 0;
}
When you start typing during the sleep_for()
, the text just shows up afterwards when std::cin
is called. I was wondering if anyone knew how to fix it and why it is happening.