C++ concatenation operand ‘+’ different form ‘ ‘.
At school*, in C++, we always used the ‘+’ operator to concatenate strings.. for example:
string a = "hello"+" world.";
But today i was coding something like this:
#define filename "./temp"
[...]
function("something "+filename);
and the compiler was not okay with this:
invalid operands to binary expression ('const char[9]' and 'const char[7]')
I later found out that writing it like:
#define filename "./temp"
[...]
function("something" filename);
made it work.
Why is that??
P.S. i feel like i should also specify that my school often mixed C things into C++.. but ‘+’ only works with c++ strings, right?
Stella Bckwrds is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.