我找到的簡單方法:
string s( (char *) a);
詳細的互相轉換的測試代碼:
char token[] = "fuck u";
uint8_t* potentialData = (uint8_t*) token;
cout << "Hello World!" << potentialData << endl;
string tis((char *)potentialData);
cout << tis << endl;
out:
Hello World!fuck u
fuck u
其他方法(來源:https://stackoverflow.com/questions/4508911/convert-uint8-t-to-stdstring-in-c)
std::string s( data, data+len );
其中len爲data的長度