c++ 字符串连接问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 03:55:17
char a[20];
char b[7];
a = "abcde";
cin >> b;
请问 a 和b怎么直接连在一起,"abcde" 这个字符穿 怎么与 b连接在一起 谢谢

#include <iostream>
//#include <string.h>

using namespace std;

int main()
{
char a[20] ="abcefg";
char b[7];
cout<<a<<endl;
cin>>b;

strcat(a,b);
// 新版本的VC最好用strcat_s来替换此函数
cout<<a<<endl;
}
/*
abcefg
hijklm
abcefghijklm
请按任意键继续. . .
*/

既然是C++为什么不纯粹C++到底?
舍弃字符数组,直接用std::string岂不是方便
直接用运算符+连接

strcat(a, b);
输入b之后将b连接到a的尾部.

<string.h>里有专门的函数,是strcat()
原型:extern char *strcat(char *dest,char *src);

strcat(a,b)