在C++中,怎么用指针字符串输入两个字符串,然后合并两个字符串啊?急求

来源:百度知道 编辑:UC知道 时间:2024/05/23 03:20:54

#include <iostream>
using namespace std;

void main()
{
char p1[2048];
char p2[1024];
cout<<"Please input str1\n";
gets(p1);

cout<<"Please input str2\n";
gets(p2);

strcat(p1,p2);
cout<<"The result is:\n"<<p1;
}

#include <iostream>
#include <string>
using namespace std;

void main()
{
string str1,str2;
cout<<"Please input str1\n";
getline(cin,str1);
cout<<"Please input str2\n";
getline(cin,str2);

str1+=str2;

cout<<str1<<endl;
}

用strcat函数
char *strcat(char *p1,char *p2);
吧字符串p2链接到字符串p1的末尾.原来的字符串末尾的NULL消去.
需要包含string.h头文件.