convert unsigned char* to String

后端 未结 1 1937
慢半拍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<char*>(name));
    

    reinterpret_cast<char*>(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)
提交回复
热议问题