我有一个文件,据说长度为8个字节.例如它看起来像这样:
22222222
现在,我首先阅读让我们说5个字节并更改它们.对于前者 至11111
最后,我想将它们写入ONTO EXCISTING DATA到文件中,所以我希望文件看起来像这样:
11111222
但我只得到11111,因为文件被删除了.如何禁用删除?(也许这个问题存在,但无法找到像这样的问题)
根据您对文件的具体操作,您可能希望对内存进行映射:
QFile f("The file");
f.open(QIODevice::ReadWrite);
uchar *buffer = f.map(0, 5);
// The following line will edit (both read from and write to)
// the file without clearing it first:
for (int i=0; i<5; ++i) buffer[i] -= 1;
f.unmap(buffer);
f.close();
Run Code Online (Sandbox Code Playgroud)