I know it is a common issue, but looking for references and other material I don't find a clear answer to this question.
Consider the following code:
#include <string>
// ...
// in a method
std::string a = "Hello ";
std::string b = "World";
std::string c = a + b;
The compiler tells me it cannot find an overloaded operator for char[dim]
.
Does it mean that in the string there is not a + operator?
But in several examples there is a situation like this one. If this is not the correct way to concat more strings, what is the best way?
This question is related to
c++
operator-keyword
string-concatenation
stdstring
standard-library
std::string a = "Hello ";
a += "World";
I would do this:
std::string a("Hello ");
std::string b("World");
std::string c = a + b;
Which compiles in VS2008.
std::string a = "Hello ";
std::string b = "World ";
std::string c = a;
c.append(b);
Source: Stackoverflow.com