怎么样连接两个char*型的字符串变量

直接见代码

#include <iostream>
using namespace std;
int main()
{
    char* str1 = "Hello";
    char*str2 = "World";
    //方式一
    char str3[20];
    strcpy(str3, str1);
    strcat(str3, str2);
    cout << str3 << endl;
    //方式二
    //char str3[20];
    sprintf(str3,"%s%s",str1,str2);
    cout << str3 << endl;
    return 0;
}

你可能感兴趣的:(C++,字符型变量的连接)