Why it is possible to do
const string exclam = \"!\";
const string str = exclam + \"Hello\" + \" world\";
And not possible to do this:
In addition to the answers that explain the reason for your observations, I post here how to get rid of the problem (you might have figured this out already).
Replace
const string str = "Hello" + " world" + exclam;
with
const string str = string("Hello") + " world" + exclam;
so you make sure the first operand is a string
and not a const char[]
.