C++ string 怎么保存二进制数据 不会截断
黄舟
黄舟 2017-04-17 14:21:13
0
5
467
C++ string 怎么保存二进制数据 不会截断

目前了解到的 有 
unsigned char 
std::vector<char>
string 目前 保存二进制的方法是用 push_back
string 不太稳定 。
string 听说还有其他 方法可以保存二进制数据  望指点。
std::vector<char> 用起来 挻不错的 
期待 更好更稳定的方法 谢谢.
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(5)
巴扎黑

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::stringThere 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:

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);

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template