Converting int[] to String in C++

前端 未结 6 1245
星月不相逢
星月不相逢 2020-12-16 06:26

I have a string defined as std::string header = \"00110033\"; now I need the string to hold the byte values of the digits as if its constructed like this

6条回答
  •  情深已故
    2020-12-16 07:12

    You can do this:

    std::string header( data_bytes, data_bytes + sizeof( data_bytes ) );
    std::transform( header.begin(), header.end(), header.begin(), 
         std::bind1st( std::plus< char >(), '0' ) );
    

提交回复
热议问题