Consider the following string definitions:
string s1 = "hello", s2 = "world";
string s6 = s1 + ", " + "world";
string s7 = "hello" + ", " + s2;
The book C++ Primer 5e states that the third line will cause the compiler to give an error because you cannot add string literals. The actual error given from the compiler is
error: invalid operands of types 'const char [6]'
and 'const char [3]' to binary 'operator+'
But isn't the second string s6
doing the exact same thing as s7
? What is the difference?