I was confused with below code snippet. What is problem with this code?
const string a = "!";
const string b = "hello" + "world" + a ;
It says "+ can't add 2 pointers".
But, if the code is changed as below, it works:
const string a = "hello";
const string b = a + "world" + "!" ;
Okay, I figured it out. For 2nd case, string concatenation occurs 2 times; but in 1st case when first 2 string literal is added it causes the problem, as '+' has left associativity.
the literal "something" is a character array ( C string ) std::string a is a class wrapper for that ( C++ string )
The C++ string library overloads the + operator to work with strings, here is a list of overloads: http://www.cplusplus.com/reference/string/operator+/
To make + work for C strings you'll need to convert one of them to a C++ string
eg: string b = string("hello") + "world" + a ;