当前位置: 代码迷 >> 综合 >> C++字符Char string字符串拼接(error c2110:“+“:不能添加两个指针)
  详细解决方案

C++字符Char string字符串拼接(error c2110:“+“:不能添加两个指针)

热度:13   发布时间:2024-02-02 00:54:22.0

char* ,char*
char* str1 = "Hello";
char*str2 = "World";
//方式一
char str3[20];
strcpy(str3, str1);
strcat(str3, str2);   //两个Char类型的字符串拼接

//方式二
//char str3[20];
sprintf(str3,"%s%s",str1,str2);   //将各种类型格式化到字符串

string,string

   string str1= "Hello";
string str2 = "World"; 

   string str3 =str1+str2;

char*, string

   char* str1 = "Hello";
string str2 = "World";

   string str3=str1;

   str3=str3+str1;

  相关解决方案