Getting a buffer into a stringstream in hex representation:

前端 未结 2 2000
说谎
说谎 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 18:01

    #include 
    #include 
    
    std::stringstream ss;
    ss << std::hex << std::setfill('0');
    for (int i = 0; i < 32; ++i)
    {
        ss << std::setw(2) << static_cast(buffer[i]);
    }
    

提交回复
热议问题