我使用了 strcpy()
函数,但它只在我使用 C 语言字符串数组时才有效:
char a[6] = "text";
char b[6] = "image";
strcpy(a,b);
但是每当我使用
string a = "text";
string b = "image";
strcpy(a,b);
我遇到了这个错误:
functions.cpp: no matching function for call to
strcpy(std::string&, std::string&)
如何在C++中复制两个字符串(类型为string)?
a=b;
:D - PiotrNyczstd :: string
类型,而不是使用strcpy
,而是使用复制赋值。 - Basile Starynkevitch