Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Updating Record.

Options
  • 26-11-2011 5: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