换行符通常是默认的输入结束标志,现在要把它作为字符存入字符串,就得另外约定一个结束符,这里设为'#'。有了这个约定,就有很多办法可以解决题面问题,下面提供一种:
//#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
}
//#include "stdafx.h"//If the vc++6.0, with this line.#include "stdio.h"
int main(void){
char a[]="1234567890",b[]="abcdefg"
printf("不添换行符:\n%s%s\n",a,b)
printf("不添换行符:\n%s\n%s\n",a,b)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)