Converting int[] to String in C++

前端 未结 6 1237
星月不相逢
星月不相逢 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条回答
  •  -上瘾入骨i
    2020-12-16 07:06

    Assuming you're using a "fairly normal" system where the numeric values of '0' to '9' are consecutive, you can just iterate over each element and subtract '0':

    for(int i = 0; i < header.size(); ++i)
    {
        header[i] -= '0';
    }
    

提交回复
热议问题