I used the strcpy() function and it only works if I use C-string arrays like:
strcpy()
char a[6] = "text"; char b[6] = "image"; strcpy(a,b);
but whenever I use
string a = "text"; string b = "image"; strcpy(a,b);
I get this error:
functions.cpp: no matching function for call to strcpy(std::string&, std::string&)
strcpy(std::string&, std::string&)
How to copy 2 strings of string data type in C++?
You shouldn't use strcpy() to copy a std::string, only use it for C-Style strings.
std::string
If you want to copy a to b then just use the = operator.
a
b
=
string a = "text"; string b = "image"; b = a;
2.1m questions
2.1m answers
60 comments
57.0k users