Getting a buffer into a stringstream in hex representation:

前端 未结 2 1982
说谎
说谎 2020-12-05 17:21

If I had a buffer like:

uint8_t buffer[32];

and it was filled up completely with values, how could I get it into a stringstream, in hexadec

相关标签:
2条回答
  • 2020-12-05 17:52

    Look at the stream modifiers: std::setw and std::setfill. It will help you.

    0 讨论(0)
  • 2020-12-05 18:01
    #include <sstream>
    #include <iomanip>
    
    std::stringstream ss;
    ss << std::hex << std::setfill('0');
    for (int i = 0; i < 32; ++i)
    {
        ss << std::setw(2) << static_cast<unsigned>(buffer[i]);
    }
    
    0 讨论(0)
提交回复
热议问题