Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Updating Record.

  • 26-11-2011 05:20PM
    #1
    Closed Accounts Posts: 2,663 ✭✭✭


    Im really am stuck with this half of the program. Seen that im no good at I/O Streams i am hoping some one could help me with this..

    what i am looking to do is Ask A User to enter a Seat No. Search the Text File. once you find that No.

    Then allow the User to Update the Name,

    Over Write the old Name in the Text file with the New Name the User Enters. but its not working

    {
                int recNumb;
                
                fstream myFile("AirLine.text", ios::in | ios::out | ios::app | ios::binary);
                myFile.seekg(0, ios::beg);
                
                cout << "Enter Passenger Seat Number:";
                cin >> recNumb;
                 
                passenger p;
                while (!myFile.eof())
                {
                    myFile.read((char*)&p, sizeof (p));
                    
                    
                
                    if(recNumb == stArray[i].seat_number)
                   {   
                 
                        cout << " Enter Passengers New Name:";
                        cin.getline(stArray[i].Newname,30);
                 
                      
                 
                   }
                 
                    
                    
                    long pos = Myfile.tellg();
                    pos -=sizeof(passenger);
                    myFile.seekp(pos,ios::beg);
                    
                     stArray[i].name = stArray[i].Newname;
                    
                    myFile.write((char*)&p, sizeof(p));
                    
                }
             
                
                       else 
                       
                       cout<<"Passenger  not found"<<endl;
                       
                     
                       myFile.close();
                       }
    
    im using char Strings.


Advertisement