How to Convert unsigned char* to std::string in C++?

前端 未结 6 1385
予麋鹿
予麋鹿 2020-11-29 02:56

I have unsigned char*, want to convert it to std::string. Can you please tell me the safest way to do this?

6条回答
  •  无人及你
    2020-11-29 03:38

    If has access to CryptoPP

    Readable Hex String to unsigned char

    std::string& hexed = "C23412341324AB";
    uint8_t      buffer[64] = {0};
    StringSource ssk(hexed, true,
                new HexDecoder(new ArraySink(buffer,sizeof(buffer))));
    

    And back

    std::string hexed;
    uint8_t val[32]  = {0};
    StringSource ss(val, sizeof(val), true,new HexEncoder(new StringSink(hexed));
    // val == buffer
    

提交回复
热议问题