error in concatenating the strings in C++

Viewed 94

When I am trying to run this code. I'm getting this error "C2110: '+' : cannot add two pointers". Can anyone just tell me what is wrong in the code?

string Msg;
getline(cin, Msg);

string output;
output = "<Rvc>\n"+"<Msg>"+Msg+"< / Msg>\n";
1 Answers

C-style string literals are not std::strings. "<Rvc>\n" and "<Msg>" are of type const char[] and could decay to pointers (i.e. const char*). Adding on pointers doesn't make sense.

You can just

output = "<Rvc>\n<Msg>"+Msg+"< / Msg>\n";

Then the overloaded operator+ for std::string taking const char* and std::string will be used.

Related