C++ having cin read a return character

前端 未结 5 1179
走了就别回头了
走了就别回头了 2021-02-07 20:17

I was wondering how to use cin so that if the user does not enter in any value and just pushes ENTER that cin will recognize this as valid

5条回答
  •  时光说笑
    2021-02-07 21:10

    You will probably want to try std::getline:

    #include 
    #include 
    
    std::string line;
    std::getline( std::cin, line );
    if( line.empty() ) ...
    

提交回复
热议问题