delete record from file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bitbyte89
    New Member
    • Nov 2008
    • 26

    delete record from file

    void delData()
    {
    int id;

    fstream delData("Depart ment1.txt",ios: :out | ios::in|ios::bi nary);
    if(!delData)
    {
    cerr<<"file could not be opened"<<"\n";
    }
    else
    {
    cout<<" Enter the ID of department you want to modify :"<<"\n";
    cin>>id;

    Department d;

    delData.seekg(( id-1)*sizeof(Depar tment));

    delData.read((c har*)(&d),sizeo f(Department));

    int iid=d.getID();
    if(iid!=0)
    {
    Department d1;
    delData.seekp(( id-1)*sizeof(Depar tment));

    delData.write(( char*)(&d1),siz eof(Department) );


    }
    else
    cout<<" Id "<<id<<" is already empty "<<"\n";
    }
    }


    can any1 please help that this also is deleting perfectly the record but the record key that is the department id is printing like
    1
    2
    4
    5
    it is deleting 3rd record but how can i get the sorted record??
Working...