string str = "ab" + 'c';
string literals cannot be concatenated like that. "ab"
is an array of character, which decays into pointer (in this context) and you're adding 'c'
which is an integral to the pointer. So the pointer is advancing by the ascii value of 'c'
.
That is, the above code is equivalent to this:
char char * s= "ab";
string str = &s['c']; //the ascii value of 'c' acts like an index to the array.
I'm sure that isn't what you intended. In fact, it invokes undefined behavior, because &s['c']
refers to a memory region which might not be in the process's address space.
The short form of what you actually want to do (i.e concatenation), is this:
string str = string("ab") + "c";