Problem of using cin twice

前端 未结 6 1036
攒了一身酷
攒了一身酷 2020-12-01 13:27

Here is the code:

string str;
cin>>str;
cout<<\"first input:\"<

        
6条回答
  •  半阙折子戏
    2020-12-01 14:06

    As others have said, th problem is that the newline is left from the first extraction. One solution I do is to discard all the left characters in the stream:

    std::cin.ignore( std::numeric_limits::max(), '\n' );
    

提交回复
热议问题