如何扫描txt文件以查找重复35个字符的行并在C ++中删除整行? [英] How do I scan a txt file to find lines that have duplicates 35 characters long and delete that whole line in C++?

查看:96
本文介绍了如何扫描txt文件以查找重复35个字符的行并在C ++中删除整行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何扫描txt文件以查找重复35个字符的行并删除整行?



我尝试过:



如何找到一个txt文件找到重复35个字符的行并删除整行?

解决方案

基本算法是:



打开输入文件进行读取访问

打开输出文件进行写入访问

从输入文件中读取文本行

评估重复

如果不重复则将该行写入输出文件

继续读写,直到找到文件结尾(读取失败)

关闭文件



此时你可以将输出文件复制到输入中,如果你想要替换它,或者如果你不想那么你就完成了。



我可能会使用fopen,fgets和文件访问的fput,但你也可以使用流if这是你最满意的。



至于代码,你必须自己写,因为它不是我的作业。 / BLOCKQUOTE>

How do I scan a txt file to find lines that have duplicates 35 characters long and delete that whole line?

What I have tried:

How do I can a txt file to find lines that have duplicates 35 characters long and delete that whole line?

解决方案

The basic algorithm is :

open the input file for read access
open an output file for write access
read line of text from input file
evaluate for duplication
if not a duplicate then write that line to the output file
continue reading and writing until end of file found (the read fails)
close the files

at this point you can copy the output file to the input if you want to replace it or if you don't want to then you are done.

I would likely use fopen, fgets, and fputs for the file access but you could also use streams if that is what you are most comfortable with.

As for the code, you have to write that yourself because it's not my homework.


这篇关于如何扫描txt文件以查找重复35个字符的行并在C ++中删除整行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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