您的位置:首页 > 其它

编写一段程序,从标准输入中读取多个字串并将他么连接起来,输出成大的字符串。 改写上述程序,用空格把输入的多个字符串分割开来。

2018-03-05 10:26 218 查看
/*
*编写一段程序,从标准输入中读取多个字串并将他么连接起来,输出成大的字符串。
*改写上述程序,用空格把输入的多个字符串分割开来。
*/
#include"stdafx.h"
#include"iostream"
#include"string"
using namespace std;
int main()
{
char cont = 'y';
string s, result;
cout << "请输入一个字符串:" << endl;
while (cin>>s)
{
//不加空格
//result += s;

//加空格
if (!result.size())//第一个拼接的字符串之前不加空格
result += s;
else
result = result + " " + s;

cout << "是或继续(y or n)?" << endl;
cin >> cont;
if (cont == 'y' || cont == 'Y')
cout << "请输入下一个字符串:" << endl;
else
break;
}
cout << "拼接后的字符串是:" << result << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐