#include
#include
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
string s, sum;
cout << "请输入多个字符串:" << endl;
while (cin >> s)
{
sum += s;
}
cout << "字符串连接起来的大字符串是:" << sum << endl;
system("pause");
return 0;
}
#include
#include
using namespace std;
int main()
{
string s, sum;
cout << "请输入多个字符串:" << endl;
while (cin >> s)
{
if(s=="#") break;
sum += s;
}
cout << "字符串连接起来的大字符串是:" << sum << endl;
system("pause");
return 0;
}
没有退出条件,所以永远在执行while循环里的内容,不会有输出。
#include "stdafx.h"
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int _tmain(int argc, _TCHAR* argv[])
{
string s, sum;
cout << "请输入多个字符串(按q键退出):" << endl;
while (cin >> s)
{
if(s=="q")
{
break;
}
sum += s;
}
cout << "字符串连接起来的大字符串是:" << sum << endl;
system("pause");
return 0;
}
正如楼上所说,while循环成了死循环,没有终止条件。