如何从C ++中的二进制文件中删除零件 [英] How to delete parts from a binary file in C++

查看:181
本文介绍了如何从C ++中的二进制文件中删除零件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从二进制文件中删除零件,使用C ++。二进制文件大约是5-10 MB。

I would like to delete parts from a binary file, using C++. The binary file is about about 5-10 MB.

我想做什么:


  1. 搜索ANSI字符串

  2. 一旦我找到这个字符串,我想删除以下n个字节,例如以下1 MB的数据。

  3. 我想将修改的文件保存到一个新的二进制文件,什么是相同的

你能给我一些建议/最好的

Can you give me some advice / best practices how to do this the most efficiently? Should I load the file into memory first?

我如何有效地搜索ANSI字符串? 我的意思是,我可能需要跳过几兆字节的数据,然后才找到该字符串。 >>我已经被告知我应该在另一个问题,因此它在这里问:
如何在二进制文件中查找ANSI字符串?

How can I search efficiently for an ANSI string? I mean possibly I have to skip a few megabytes of data before I find that string. >> I have been told I should ask it in an other question, so its here: How to look for an ANSI string in a binary file?

删除n个字节并有效地写入新文件?

好的,我不需要它是超级有效的,文件不会

OK, I don't need it to be super efficient, the file will not be bigger than 10 MB and its OK if it runs for a few seconds.

推荐答案

有很多快速字符串搜索例程执行比测试每个字符更好。例如,当试图找到某事时,只有每第9个字符需要测试。

There are a number of fast string search routines that perform much better than testing each and every character. For example, when trying to find "something", only every 9th character needs to be tested.

这是一个我为早期问题写的例子:代码审查:查找< / body>在非空终止的char str 上标记反向搜索

Here's an example I wrote for an earlier question: code review: finding </body> tag reverse search on a non-null terminated char str

这篇关于如何从C ++中的二进制文件中删除零件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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