我有一个文件,假设长度为 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();
关于c++ - QFile/QDataStream 写入现有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3422702/