convert unsigned char* to String

后端 未结 1 1939
慢半拍i
慢半拍i 2020-12-14 00:22

I am little poor in type casting. I have a string in xmlChar* (which is unsigned char*), I want to convert this unsigned char to a std::string type

1条回答
  •  时光取名叫无心
    2020-12-14 01:10

    std::string sName(reinterpret_cast(name));
    

    reinterpret_cast(name) casts from unsigned char* to char* in an unsafe way but that's the one which should be used here. Then you call the ordinary constructor of std::string.

    You could also do it C-style (not recommended):

    std::string sName((char*) name);
    

    0 讨论(0)
提交回复
热议问题