简体   繁体   中英

Convert const Byte* to std::string c++

How can i convert const Byte* to std::string.I tried the following

std::string sTemp(reinterpret_cast<const char*>(ByteBuffer));

Where ByteBuffer is const Byte*.Not got the value of ByteBuffer in sTemp using the above code Please help

Thanks,

If ByteBuffer contains a NUL-terminated string, then the code should work fine.

If it doesn't, you need to supply its length as the second parameter to the string constructor .

The above assumes that Byte is what I think it is, and that ByteBuffer is not NULL .

There's no such data type as 'Byte' in C++. I assume it's a 8-bit data store if at all it exists, in which case your code is correct. Make sure there's a null character - '\\0' in the buffer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM