C++字符缓冲区指针错误
问题描述:
我正在使用读取假脱机文件并使用输出设置缓冲区的函数。 函数返回OK状态并正确设置readBytes
。它还通知阅读操作已到达文件的末尾。C++字符缓冲区指针错误
char* splFileContent = new char[3000];
ULONG readBytes;
int z = cwbOBJ_ReadSplF(splFile, splFileContent, 500, &readBytes, 0);
//z value is REACHED END OF FILE or OK if read but didn't reach the end of the file.
的麻烦来试图将字符缓冲区字符串,我得到“4A”转换为字符串值时...
我的字符缓冲区这种方式转换成字符串:
stringstream s;
s << splFileContent;
string bufferContent = s.str();
我在做什么错了?
答
看起来像splFileContent
是二进制内容而不是可打印字符。
该文件的开始可能包含某种类型的BOM,例如, unicode指标。如果是这样,您应该首先阅读物料清单,然后阅读文件的其余部分。
注意:除非文件读取功能在这里添加NULL
,否则一定要附加一个。
+1
将字符串转换为ascii?谢谢。 – ProtectedVoid
+1
通常,将字节宽二进制数转换为两个字节宽的十六进制字符串(每个字符的范围为[0-9A-F])。你可以使用流,sprintf函数等。有几种流行的技术。 – Niall
您可以使用'string bufferContent(splFileContent,readBytes);' – marom