Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 写入文件';最后32个字符_C++_File_Ofstream_File Processing - Fatal编程技术网

C++ 写入文件';最后32个字符

C++ 写入文件';最后32个字符,c++,file,ofstream,file-processing,C++,File,Ofstream,File Processing,我想在二进制文件的最后32个字符中写入一个信息。但是当我调用writeInfo函数时,它会删除整个内容。我可以在写之前读取数据,但在使用此函数写之后,它会删除整个内容,而不是写入 void Info::writeInfo(char *filedestination) { ofstream test; test.open(filedestination, ios::binary); test.seekp(-32, ios::end); // not sure about seekp test.w

我想在二进制文件的最后32个字符中写入一个信息。但是当我调用writeInfo函数时,它会删除整个内容。我可以在写之前读取数据,但在使用此函数写之后,它会删除整个内容,而不是写入

void Info::writeInfo(char *filedestination)
{
ofstream test;
test.open(filedestination, ios::binary); 
test.seekp(-32, ios::end); // not sure about seekp
test.write(info, 31);
test.close();
}
希望你能帮忙,谢谢你


尝试使用fseek()。上面的链接是文档

您必须以读写模式打开文件,以防止调用
打开
将其截断:

test.open(filedestination, ios::binary | ios::in | ios::out); 

这是他已经在使用的seekp的C等价物。C和C++混合也是个坏主意。