写入文件的最后 32 个字符
Write to File's Last 32 Characters
我想写一个信息二进制文件的最后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();
}
希望你能帮忙,谢谢
您必须以读写模式打开文件,以防止对open
的调用截断它:
test.open(filedestination, ios::binary | ios::in | ios::out);
http://www.cplusplus.com/reference/cstdio/fseek/
尝试使用fseek()。上面的链接是文档
相关文章:
- 仅读取文件末尾的最后 3 个字符,并将其另存为 int
- 使用连续分隔符和空最后一个字符进行拆分
- CPP:如何获取字符的最后一个索引
- 如何检查字符串中的最后一个字符是否是某个字符并将其从字符串中删除?(C++)
- 比较最后一个字符,不区分大小写(带谓词?
- 在弦乐器中删除最后一个字符
- 输入文件中的第一个字符是输出文件中的最后一个字符,反之亦然
- 在C 字符串中,为什么在最后一个字符之后,通过索引和()访问索引时行为是不同的
- 如何查看复杂度为 O(1) 的字符串流对象中的最后一个字符
- 最后一个字符行编辑
- C 字符串副本()在最后给我额外的字符,为什么是这样
- 仅当捕获组最后一次出现时,才使字符成为可选字符
- 如何在C 中获得字符串的最后一个字符
- 从字符串中删除字符的第一个和最后一个实例
- 删除文件 C++ 中字符串中最后一个出现的字符
- 如何在C++中删除 UTF-8 字符串的最后一个字符
- 如何将文本(诗歌)拆分为行(字符串/字符[])并查找每个行的最后一个单词
- 如何获取输入文件的行的第二个和最后一个字符,并在C++中组成数组
- 删除字符C++最后一次出现时字符数组的开头
- 返回常量字符数组中字符最后出现的索引