C++: how do I check if the cin buffer is empty?

后端 未结 4 448
梦谈多话
梦谈多话 2020-12-23 20:08

How do you check to see if the user didn\'t input anything at a cin command and simply pressed enter?

4条回答
  •  独厮守ぢ
    2020-12-23 21:12

    int main(){ 
    string str[100];
    std::cout<<"Hello how are you ? \n";
    std::cin>>str;
    if(str.length() > 0){
    // If input is seen
    }
    else{
    // If input is not seen
    }
    }
    

    Any problem let me know.

提交回复
热议问题