How to make reading from `std::cin` timeout after a particular amount of time

后端 未结 3 441
别那么骄傲
别那么骄傲 2020-11-27 22:40

I have written a small program,

int main(int argc, char *argv[])
{
    int n;
    std::cout << \"Before reading from cin\" << std::endl;

    //          


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 23:11

    This works for me (note that this wouldn't work under Windows though):

    #include 
    #include 
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int n;
        cout<<"Before performing cin operation"<>n) : false;
    
        if(b==1)
              cout<<"input is integer for n and it's correct"<

提交回复
热议问题