sting tmp;
while(getline(cin,tmp))
cout<<tmp<<endl;为什么连续两次回车后while循环不退出呢?

解决方案 »

  1.   

    应该没什么问题啊,上面sting tmp应该是打错了吧
      

  2.   

    sting tmp改为
    string tmp;
    不能退出循环呀
      

  3.   


    template<class CharType, class Traits, class Allocator>
       basic_istream<CharType, Traits>& getline(
          basic_istream<CharType, Traits>& _Istr,
          basic_string<CharType, Traits, Allocator>& _Str
    );The first function returns getline( _Istr, _Str, _Istr.widen( '\n' ) ). 
      

  4.   

    长度为0的string也是有效的。
    加判断:
    while(getline(cin,tmp))
    {
    if(0 == tmp.length())
    {
    break;
    }
    cout<<tmp<<endl;
    }
      

  5.   


    只能这样吗? 难道getline就是这么设计的?
      

  6.   


    getline 是这样要求退出的吗?
      

  7.   


    是的
    Ctrl+Z就相当于文件结束符eof
      

  8.   

    windows下crtl+z linux下ctrl+d 详细的你可以看一下下面的文章
    http://www.javaeye.com/wiki/topic/686817