01:#include "stdafx.h"
02:#include <iostream>
03:#include <string>05:using std::cout;
06:using std::cin;
07:using std::endl;
08:using std::string;10:string s1;12:int _tmain(int argc, _TCHAR* argv[])
13:{
14:    string s;      
15: while(getline(cin,s))               
16: cout<<s1<<endl;          
17: cout<<s<<endl;
18: return 0;
19:}

解决方案 »

  1.   

    while(getline(cin,s))              
     cout < <s1 < <endl;  //只要cin输入成功,就会一直循环啊,连续两个回车推出循环    
      

  2.   

    getline(cin,s) 等价于 getline(cin, s, '\n')
      

  3.   

    你想要怎么执行?把while去掉?
      

  4.   

    15: while(getline(cin,s))              
    16: cout < <s1 < <endl;  等于:
    //
    15: while(getline(cin,s))
    {              
        16: cout < <s1 < <endl; 
    }
    getline(cin,s)总是有,当然不会到17了. 
      

  5.   

    楼主说的是15,16行循环吗是因为楼主的while操作
      

  6.   

    判断一下输入的字符,如果为某一字符时,跳出while15: while(getline(cin,s)) 
    {              
      if (s!='x')
        cout < <s1 < <endl; 
      else
        break;