我正在尝试读取一个二进制文件并将其存储在缓冲区中。问题在于,该二进制文件中有多个以null终止的字符,但它们不是在末尾,而是出现在其他二进制文本之前,因此如果我在'\0'后面存储文本,它会在缓冲区中将其删除。
例如:
char * a = "this is a\0 test";
cout << a;
这将只输出:
this is a
这是我的真实代码:该函数读取一个字符。
bool CStream::Read (int * _OutChar)
{
if (!bInitialized)
return false;
int iReturn = 0;
*_OutChar = fgetc (pFile);
if (*_OutChar == EOF)
return false;
return true;
}
这是我如何使用它:
char * SendData = new char[4096 + 1];
for (i = 0; i < 4096; i++)
{
if (Stream.Read (&iChar))
SendData[i] = iChar;
else
break;
}