String concatenation my ...?

According to this link: String concatenation

I think this line should be OK:

String x = "Start pumpe " + p + " !"; // p is an Int !!!!!!!!

but no, no, this error message comes up:

invalid operands of types 'const char*' and 'const char [3]' to binary 'operator+'

I wonder it should be sophisticated to concatenate a string !

I know there is other ways to do it - but why not use the easy one - is there an error here or what's wrong ?

try this:
String x = "Start pumpe " + String(p) + " !";

But is that what the link says ????

Yes, the link says you can use the + operator with a String instance. "Start pumpe " Is not, it’s a cString (a string literal )

Always remember that the type on the left side of the '=' has nothing to do with how the right side of the '=' is evaluated. That's why "long foo = 1000 * 1000;" is not the same as "long foo = 1000000;". In the first one, you get an overflow with 16-bit integers and with the second the compiler knows you mean '1000000L' because '1000000' won't fit in a 16-bit 'int'.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.