C++ unsigned char*轉化為string的形式

MY CUP OF TEA發表於2020-10-12

 unsigned char*轉化為string

int main(int argc,char **argv){
    //unsigned char * 轉化為string
    //參考連結 https://www.itdaan.com/tw/4ff531a5e6651468a5b7c6d95927ba3d
    unsigned char *foo;
    unsigned char str[] = "Hello world";
    string strHH;
    foo = str;
    strHH.append(reinterpret_cast<const char*>(foo));
    cout << strHH << endl;

}

輸出結果

 參考連結

 

相關文章