两个char*型的字符串变量拼接操作

tech2025-07-07  1

示例代码 #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; }

 

最新回复(0)