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. :)

Recommended Answers

All 4 Replies

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

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).

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;
commented: Perfect!! +1

Thanks mitrmkar, you gave the perfect solution,

strcat(variable1, variable2.c_str());

works perfectly!! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.