如何在c ++中只覆盖部分文件 [英] How to overwrite only part of a file in c++

查看:240
本文介绍了如何在c ++中只覆盖部分文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用c ++对文本文件的中间进行修改,而不改变文件的其余部分。

I want to make modifications to the middle of a text file using c++, without altering the rest of the file. How can I do that?

推荐答案

如果替换字符串的长度相同,则可以进行更改。如果替换字符串较短,则可以使用零宽度空格或类似字符填充替换字符串,以使其具有相同的字节数,并进行更改。如果替换字符串较长,则只有没有足够的空间,除非您先移动所有剩余的数据。

If the replacement string is the same length, you can make the change in place. If the replacement string is shorter, you may be able to pad it with zero-width spaces or similar to make it the same number of bytes, and make the change in place. If the replacement string is longer, there just isn't enough room unless you first move all remaining data.

这篇关于如何在c ++中只覆盖部分文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆