C++ string 怎么保存二进制数据 不会截断 目前了解到的 有 unsigned char std::vector<char> string 目前 保存二进制的方法是用 push_back string 不太稳定 。 string 听说还有其他 方法可以保存二进制数据 望指点。 std::vector<char> 用起来 挻不错的 期待 更好更稳定的方法 谢谢.
人生最曼妙的风景,竟是内心的淡定与从容!
You can use base64 to encode binary data into a string and save it.
Also std::bitsetbut it may not be what you want.
std::bitset
std::stringThere is no problem in saving binary, you must be using it incorrectly.
std::string
Suppose you have obtained a char * buffer and want to put it into a string, then you can do this:
char *
string str(buf, buflen);
However, I don’t know what the benefit of doing this is. .
for binary buffer implementation, refer to the Slice in leveldb: leveldb source code analysis Slice class
Thank you for your answers. This problem has been solved...I used string.append(content,size);
You can use base64 to encode binary data into a string and save it.
Also
std::bitset
but it may not be what you want.std::string
There is no problem in saving binary, you must be using it incorrectly.Suppose you have obtained a
char *
buffer and want to put it into a string, then you can do this:However, I don’t know what the benefit of doing this is. .
for binary buffer implementation, refer to the Slice in leveldb:
leveldb source code analysis Slice class
Thank you for your answers. This problem has been solved...I used string.append(content,size);