注册 登录
编程论坛 C++教室

[求助]一个关于string连接的问题

木木秋 发布于 2007-01-12 15:39, 594 次点击

请教各位:
编一个程序,从标准输入读取多个string对象,把它们连接起来存放到一个更大的string对象中,并输出连接后的对象。
我写的程序:
#include<iostream>
#include<string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
string word,bword;
cout<<"Enter several strings: "<<endl;
while(cin>>word)
{
if(word=="quit")break;
bword+=word+" ";
}
cout<<"All the strings bounded is: "<<bword<<endl;
return 0;
}
只能完成在打入“quit”后显示连接后的string对象并退出程序,请问怎样才能在输入回车后做到显示连接后的string对象并退出程序呢?

1 回复
#2
caiqiufu2007-01-13 10:56

/*编一个程序,从标准输入读取多个string对象,把它们连接起来存放到一个更大的string对象中,并输出连接后的对象。
我写的程序:*/
#include<iostream>
#include<string>
using namespace std;
//using std::cout;
//using std::cin;
//using std::endl;
//using std::string;
int main()
{
string word,bword;
cout<<"Enter several strings: "<<endl;
while(cin>>word)
{
if(word=="quit")break;
bword+=word+" ";
}
cout<<"All the strings bounded is: "<<bword<<endl;
return 0;
}
//只能完成在打入“quit”后显示连接后的string对象并退出程序,请问怎样才能在输入回车后做到显示连接后的string对象并退出程序呢?

1