编写一段程序,从标准输入中读取多个字串并将他么连接起来,输出成大的字符串。 改写上述程序,用空格把输入的多个字符串分割开来。
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;
}
*编写一段程序,从标准输入中读取多个字串并将他么连接起来,输出成大的字符串。
*改写上述程序,用空格把输入的多个字符串分割开来。
*/
#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;
}
相关文章推荐
- 编写一段程序从标准输入中读入多个字符产并将他们连接在一起,输出连接成的大字符串
- 编写一段程序,从标准输入读取string对象的序列直到连续出现两个相同的单词或者所有单词都读完为止。使用while循环一次读取一个单词,当一个单词连续出现两次是使用break语句终止循环。输出连续重复出现的单词,或者输出一个消息说明没有人任何单词是重复出现的。
- 【c语言】编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。在编写这个程序的时候要使这个程序能够处理的输入行的长度没有限制。
- 从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。在编写这个程序的时候要使用让这个程序能够处理的输入行的长度没有限制。
- 编写程序从标准输入读取几行输入。每行输入都打印在标准输出上,且前面加上行号
- 编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。在编写这个程序的时候要使这个程序能够处理的输入行的长度没有限制
- 编写一个函数,从实参传来一个字符串,统计其中字母,数字,空格和其他字符的个数,在主函数中输入字符串以及输出上述的结果
- 用java编写一个简单的字符串加密解密程序,将字符串分成若干行,实现字符串以一列一列读取,并还原之前输入的字符串。这里实现4行输出。
- C语言 编写一个程序从标准输入读取字符,并把他们写到标准输出。除了大写字母转换成小写字母之外,其他的原样输出。
- C语言 编写一个程序从标准输入读取字符,并把他们写到标准输出。除了大写字母转换成小写字母之外,其他的原样输出。
- ASCII码的应用(.编写一个程序从标准输入读取字符,并把他们写到标准输出。除了大写字母转换成小写字母之外,其他的原样输出。)
- 编写一个程序,从标准输入读取一些字符,并把它们写到标准输出上。它同时应该计算checksum值,写在后面
- 编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。
- 从标准输入中读取几行输入,每行输入都要打印到标准输出上,前面要加上行号。在编写这个程序时要是图让程序能够处理的输入行的长度没
- p16.2编写一个程序,从标准输入读取几行输入,每行输入都要打印到标准输出上,前面要加上行号,书入行的长度没有限制
- 编写一个程序从标准输入读取字符,并把它们写到标准输出。除了大写字母转化成小写字母之外,其他的原样输出。
- 习题 7.9 编写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格、和其他字符的个数,在主函数中输入字符串以及输出上述的结果。
- 编写一个程序,从标准输入读取字符,并把它们写到标准输出中。除了大写字母字符要转化为小写字母之外,所有字符的输出形式应该和他的输入形式完全相同
- 编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。
- 【C语言】编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。编写这个程序的时候要使这个程序能够处理的输入行的长度没有限制。