换行符通常是默认的输入结束标志,现在要把它作为字符存入字符串,就得另外约定一个结束符,这里设为'#'。有了这个约定,就有很多办法可以解决题面问题,下面提供一种:
//#include "stdafx.h"//If the vc++6.0, with this line.
#include <string>
#include <iostream>
using namespace std;
int main(void){
string s;
char x;
while((x=cin.get())!='#')//输入#结束,其他字符继续
s+=x;
cout << s << endl;
return 0;
}