5

I am making an Arduino alarm. This is the error:

exit status 1
invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'

Here is the code that triggers it:

lcd.print("0"+hours+":"+minutes);

This code is similar, but worked before:

String none="00";
lcd.print(none+":"+none+":"+minutes);

I can post the full code if you need it. How can this be fixed?

1 Answer 1

7

Your first code took a String object, then added other strings (note lowercase) to it - which are characters enclosed in quotes. It is legal to add strings to String objects.

Your new code doesn't have any String objects at all - and you're not allowed to add strings to strings (both lowercase).

It will work if you change your new code to:

lcd.print(String("0")+hours+":"+minutes);

That turns the original string "0" into a String object, and then adds more strings to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.