使用fstream在C ++文件中覆盖数据 [英] Overwriting Data in a C++ File using fstream

查看:306
本文介绍了使用fstream在C ++文件中覆盖数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我要覆盖特定文件中的内容(对象)我已设置位置,但它总是添加到文件的结尾

Hi i want to overwrite the content(object) in a specific file i have set the position but it always add to the end of the file

代码



Code

 int InputIO::editPatient(int location,Obj P){

        int positon=location*sizeof(P);
        f.open("File.dat",ios::in|ios::out|ios::app|ios::binary|ios::ate);
        f.seekp(0,ios::beg);
        f.seekp(positon,ios::cur);
        f.write((char*)&P,sizeof(Movie));
        f.close();

        return 0;



        }


推荐答案

只要解决这个问题就要删除ios :: app(Append)Append总是添加到文件的结尾

Just solve this have to remove ios::app (Append) Append always add to the end of the file

这篇关于使用fstream在C ++文件中覆盖数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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