I am trying to convert a printf
output to a std::string
variable. I have the following for loop:
for(i=0; i<53; i++) {
printf("%02X", pbRecvBuffer[i]);
}
The output of this loop are hex values like: 01445420434F2..
. My first attempt was using stringstream
as the following:
stringstream os;
for(i=0; i<53; i++)
os << std::hex << pbRecvBuffer[i];
std::cout << os << std::endl;
unfortunately this is given me the wrong result. Maybe someone just see it directly and can help me out.
pbRecvBuffer
? What is the result? Simply saying that you get the wrong result won't get you any useful answers.std::hex
is what you want. Just write it to the stream usingstd::cout << std::hex << your_hext_here;