I want to write binary bytes (for example, 0xAA and 0xDD) into a stringstream.
const uint8_t sync_word_1 = 0xAA;
const uint8_t sync_word_2 = 0xDD;
std::stringstream ss;
ss.write((char*)&sync_word_1, sizeof(sync_word_1));
ss.write((char*)&sync_word_2, sizeof(sync_word_2));
// print for debug
for (int i = 0; i < ss.str().size(); i++) {
printf("0x%02X ", ss.str()[i]);
}
What I expect:
0xAA 0xDD
What I got:
0xFFFFFFAA 0xFFFFFFDD
What did I miss?