#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
int count;
cin>>count;
string s;
string temp;
cin.ignore();
for(int i=0;i<count;i++)
{
getline(cin,temp);
s.append(temp);
}
cout<<s;
return 0;
}
这样就可以在循环中多次输入了,因为在程序中输入换行将导致结束。
本文介绍了一段使用C++实现的程序,该程序通过循环接收用户输入,并将所有输入内容连接成一个字符串。详细解释了如何在C++中使用cin、getline等函数进行数据读取与字符串操作。

1万+

被折叠的 条评论
为什么被折叠?



