0

Normally if I want to concantinate two strings I would use:

strcat (variable_name, "Constant");

But is there a function that let's me use (variable1, variable2) ?

Any help is welcome. :)

3
Contributors
4
Replies
6
Views
9 Years
Discussion Span
Last Post by CodeBoy101
0

Does strcat(variable1, variable2) not do what you want?

Actually no, I get an error message saying:
"cannot convert from std::string to const char."

The parameters for strcat are: (char*, const char).

1

Actually no, I get an error message saying:
"cannot convert from std::string to const char."

The parameters for strcat are: (char*, const char).

I assume variable2 is std::string, in which case you are to use:

strcat(variable1, variable2.c_str());

Just in case you are not too familiar with std::string, you can avoid strcat() completely, by simply:

std::string variable1 = "something" ;
std::string variable2 = " else";
// concatenate the strings
variable1 += variable2;
Votes + Comments
Perfect!!
0

Thanks mitrmkar, you gave the perfect solution,

strcat(variable1, variable2.c_str());

works perfectly!! :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.