std::string vs String ? #32
Replies: 2 comments 1 reply
-
|
After reading/learning a bit more I guess I have to correct myself. Both String and std::string used in this code seem to be part of the ESP32 core itself. The question arose from my willing to finally being able to read and understand this source code, and I'm slowly getting a grip with it. |
Beta Was this translation helpful? Give feedback.
-
|
Note the two are not interchangeable in this Code, as I discovered to my peril earlier. std::string is used here as a poor mans byte buffer to build the advertising packet. This works with the std string as the bytes are naively appended to the underlying char array. If you change it to the arduino String, it will stop working because when appending anything other than a char, that class will convert the value to a string representation. So e.g. when you try to append a 0x6 from a byte array, you end up adding the UTF-16 encoding of the number 6 instead (arduino bytes are unsigned chars notnregularl chars). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a minor technical question that experienced coders (which I'm definitely not) would surely answer with specific clarity.
Both
Stringandstd::stringclasses are being used here. As I understandStringis the Arduino standard class andstd::stringis the one provided by the esp32 core. Is that right?Beta Was this translation helpful? Give feedback.
All reactions