如何从C ++删除记录 [英] how to delete the record from the c++

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

问题描述

请帮助我在c ++的任何项目中通过c ++编码从.txt文件中删除记录

推荐答案

1)打开使用CStdioFile读取的现有文件
2)使用临时名称打开一个新文件进行写入
3)读取第一个文件,然后逐行复制到第二个文件,跳过要删除的行
4)到达第一个文件的末尾时关闭两个文件
5)删除第一个文件
6)将2d文件重命名为旧文件的名称.

自由地散布一些错误处理(例如在删除第一个文件之前检查第二个文件是否正常)
1) Open existing file using CStdioFile for reading
2) Open a new file with temporary name for writing
3) Read first file and copy line by line to second file, skipping lines you want to delete
4) Close both files when reached the end of first file
5) Delete the first file
6) Rename 2d file into the old file''s name.

Liberally sprinkle some error handling (like checking that second file is ok before deleting the first one)


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

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