Im really pants aint i???
ok - i asked a while ago how file i/o works and i got the prefect response - thanks fellas.
I got another query now however.......
ive got a program that enters details into a formatted output text file. I now want to search that text file for a match to certain criteria (surname to be exact) and recall the set of details for that person so they can be edited and then appended to the file.
Im using a struct to specify the data formats i want thus:
i know most peeps dont use the string operator but im having to se it as part of my course and it works well enough on Borland C++ 4.5Code:struct EditDetailsType { int iBookingNumber; int iPrice; string sSurname; string sFirstName; int iHouseNumber; string sRoad1; string sRoad2; string sCounty; string sPostCode; string sDestination; string sFlightNumber; }Recall;
The output for the file once the details have been entered is thus:
Id appreciate it if someone could tell me how to search the file ive created for the Booking.sSurname field.Code:ofstream file; file.open("booking.txt", ios::app); if (file.fail()) { cout << "File Open Failed (booking.txt). Program Halted"; int iStatus = 0; exit(iStatus -0); // this will stop the program } else { file << "\n"; file << "BOOKING #: " << Booking.iBookingNumber << "\n"; file << "CUSTOMER NAME: " << Booking.sFirstName << " " << Booking.sSurname << "\n"; file << "ADDRESS: " << Booking.sRoad1 << Booking.sRoad2 << "\n"; file << " " << Booking.sCounty << "\n"; file << " " << Booking.sPostCode << "\n"; file << "PRICE: " << Booking.iPrice << "\n"; file << "DESTINATION: " << Booking.sDestination << "\n"; file << "FLIGHT #: " << Booking.sFlightNumber << "\n"; file.close(); }
Thanks in advance (and i sure as hell hope this makes sense)
Cat



LinkBack URL
About LinkBacks




