file processing, delete certain data

This is a discussion on file processing, delete certain data within the C++ Programming forums, part of the General Programming Boards category; would anyone help me to settle this function? for your information, i want to delete certain information from the database. ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    1

    file processing, delete certain data

    would anyone help me to settle this function?
    for your information, i want to delete certain information from the database.

    example in the the database is name, address, and room number
    i just want to edit the room number of certain person from the database, anyone who know how to do that please tell me later.

    thanx in advance.





    Code:
    void buyticket(int m){
    
    	fstream ticket("cruise.dat", ios::in | ios::out); //open patient's file
    	if(!ticket)
    	{
    		cout<<"File could not be opened to read."<<endl;
    		exit(1);
    	}
    	ticket.seekg(0);
    	ship data;
    
    	ticket.seekg(   (m-1) * sizeof(ship)   );
    	ticket.read((char *)&data, sizeof(ship));
    	cout<<"Available ticket : "<< data.return_room() <<endl;
    
    
    		
    		int avalroom,befroom;
    		cout<<"Enter room : "<<endl;
    		cin>>avalroom;
    		befroom=data.return_room();
    
    		room=befroom-avalroom;
    
    		cout<<"After : "<<room<<endl<<endl;
    
    		ticket.seekp(   (m-1) * sizeof(ship)   );
    		ticket.write((char *)&data,sizeof(ship));//write into the binary file
    		cout<<"Record Modified!"<<endl;
    
    	ticket.close();
    	getch();
    }

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    What you should do IMO is create a class or a struct with all the data you need for the person. Read everything into an array or a std::vector, change it there, and then overwrite the file with the modified data.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-07-2007, 11:24 PM
  4. Writing and modifying data in a file
    By Micko in forum C Programming
    Replies: 2
    Last Post: 02-17-2005, 02:42 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21