strcat function error

Hello,


i have 2 strings, str1 and str2, and i use the strcat() function :

strcat(str1 , str2);

but i receive the error :

error: cannot convert `std::string' to `char*' for argument `1' to `char* strcat(char*, const char*)'


any idea how to solve it ?

Thanks .
Last edited on
strcat(str1.c_str() , str2.c_str());

But actually if you have C++ string, you can just use str1 + str2 can already. No need to use C functions like strcat, strcmp etc.
strcat(str1.c_str() , str2.c_str());

does not work . i receive the errors :

error: invalid conversion from `const char*' to `char*'
error:   initializing argument 1 of `char* strcat(char*, const char*)'



However, the str1 + str2 is working perfect !
In case you want strcat again try below

strcat(const_cast<char *>(str1.c_str()) , const_cast<char *>(str2.c_str()) );
Topic archived. No new replies allowed.