I am currently working with an embedded system that will be communicating to various devices using serial communication. I use a uint8_t
variable for the buffers sent and received by the embedded board. I need to modify these values (preferably using string
) and then convert them back to uint8_t
after they have been modified. I have created a simple test code for messing around with uint8_t
's and strings
. The problem I am having is the output from cout
only displays "GREE" (regardless of the value of myString
, it is always only 4 characters for some reason). I have tried a few ways to accomplish this task and would really appreciate some help. Maybe I'm missing something that's easy to fix? I've been on the computer for almost 8 hours.
string myString = "GREETINGS";
const uint8_t *p = reinterpret_cast<const uint8_t*>(myString.c_str());
myString.assign(p, p + sizeof(p));
cout << myString << endl;
OUTPUT IS: GREE