I want to know the reason for this error in EASY words please.
#include <iostream>
#include <string>
int main()
{
std::string exclam = "!";
std::string message = "Hello" + ", world" + exclam;
std::cout << message << std::endl;
return 0;
}
test.cpp:55:35: error: invalid operands to binary expression ('const char *' and 'const char *') std::string message = "Hello" + ", world" + exclam;
"Hello"
and ", world"
aren't strings, they are const char *
which as no overload for the +
operator.
You would have to do something like this:
std::string message = std::string("Hello") + std::string(", world") + exclam;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With