E
E
Emil2022-01-06 22:00:02
Arduino
Emil, 2022-01-06 22:00:02

How to fix invalid operands of types 'const char*' and 'const char [7]' to binary 'operator+' error?

Hello. I am writing a web interface for the eeprom parser for esp8266.
When compiling it says:

In function 'void rw_eeprom()':
1Both_mode:121:187: error: invalid operands of types 'const char*' and 'const char [7]' to binary 'operator+'
  121 |               server.send(200, "text/html", "<title>R/W Eeprom</title><link rel=\"stylesheet\" href=\"/style.css\"> <h1 style=\"text-align:center\">Read - Success! </h1> <br><pre>"+(val)+"</pre>");
      |                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
      |                                                                                                                                                                                     |      |
      |                                                                                                                                                                                     |      const char [7]
      |                                                                                                                                                                                     const char*
exit status 1
invalid operands of types 'const char*' and 'const char [7]' to binary 'operator+'

I don't have any char/unsigned char in my code, only byte and string.
The code:
byte val = EEPROM.read(server.arg("addr").toInt());
              server.send(200, "text/html", "<title>R/W Eeprom</title><link rel=\"stylesheet\" href=\"/style.css\"> <h1 style=\"text-align:center\">Read - Success! </h1> <br><pre>"+val+"</pre>");
        return;

I ask someone who understands Arduino and Esp-compatible boards, or at least C ++ 11 (if the arduino does not have a standard std library) please help.
What and where am I doing wrong and where can I convert this byte to a string?
Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Zaitsev, 2022-01-07
@MrCheatEugene

In server.send, replace val with (String)val
This way you convert the variable to a string type that can be added to a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question