我需要读取二进制数据进行缓冲,但在 fstreams 中我已经读取函数将数据读入 char 缓冲区,所以我的问题是:
如何将二进制数据传输/转换为 unsigned char 缓冲区,在这种情况下它是最佳解决方案吗?
例子
char data[54];
unsigned char uData[54];
fstream file(someFilename,ios::in | ios::binary);
file.read(data,54);
// There to transport **char** data into **unsigned char** data (?)
// How to?
最佳答案
先读入unsigned char数据就可以了
unsigned char uData[54];
fstream file(someFilename,ios::in | ios::binary);
file.read((char*)uData, 54);
强制转换是必要的但无害。
关于c++ - 使用fstream方法读取二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20168313/