how to override text file data in C++ -
i'm creating hotel management program in c++, i'm having trouble appending or fixing guest's completed info file.
the file saved text file. when user wants alter guest's info, tell program want alter, i.e. name. program clear name, , prompt user first name , surname of guest. program asks user if want info saved file. if user says yes, file saved.
in theory, file should changed, happens, whole new file created.
void alterinfo() { system ("cls"); string alter; char filename [100]; ifstream file_ptr; cout << "\n\t\t\t\tsaved members:\n\n"; system ("dir/b *."); cout << "\n\nplease type name of member you\n"; cout << " wish open appears above or\n"; cout << " type z (lower case) return main menu: "; //cin.ignore(); gets (filename); /*if (filename == "z") { system("pause"); }*/ if (filename[0] != 'z') { char saveyn; //cout<< "\nplease enter 6 digit registration access code: "; //cin>>rac; //if (rac == (file_ptr, membershipnumber)) //{ file_ptr.open(filename,ios::in); // char in_char; while(!file_ptr) { cout << "member not exist\n"; gets (filename); file_ptr.open(filename,ios::in); } getline(file_ptr, name); getline(file_ptr, surname); file_ptr >> address1; getline(file_ptr, address2); // duplicate required eliminate getline(file_ptr, address2); // empty field bug when using string after integer. getline(file_ptr, address3); getline(file_ptr, address4); getline(file_ptr, postcode); getline(file_ptr, telday); getline(file_ptr, televe); //file_ptr >> telday; //file_ptr >> televe; file_ptr >> indate>> inmonth>> inyear>> outdate>> outmonth>> outyear>> roomnumber>> membershipnumber; getline(file_ptr, membershiptype); // duplicate required eliminate getline(file_ptr, membershiptype); // empty field bug when using string after integer. getline(file_ptr, membernotes); guestform(); greentext(); whitetext(); file_ptr.close(); system("pause"); cout<< "\n\nwhat want alter (ex. name, address, etc): "; getline(cin, alter); if (alter == "name") { ofstream myfile; resetguestname(); guestform(); cout << "\tplease enter guest's first name: "; cin >> ws; getline (cin, name); guestform(); cout << "\tplease enter guest's surname: "; cin >> surname; guestform(); cout << "\tsave these details file? <y/n> "; //confirmation before saving file cin >> saveyn; if (saveyn == 'y' || saveyn == 'y') { string savefilename; stringstream out; out << name << " " << surname; savefilename = out.str(); ofstream myfile; //save file structure myfile.open (savefilename.c_str(), ios::out); myfile << name << "\n"; myfile << surname << "\n"; myfile << address1 << "\n"; myfile << address2 << "\n"; myfile << address3 << "\n"; myfile << address4 << "\n"; myfile << postcode << "\n"; myfile << telday << "\n"; myfile << televe << "\n"; myfile << indate << "\n"; myfile << inmonth << "\n"; myfile << inyear << "\n"; myfile << outdate << "\n"; myfile << outmonth << "\n"; myfile << outyear << "\n"; myfile << membershipnumber << "\n"; myfile << membershiptype << "\n"; myfile << membernotes << "\n"; //std::remove( myfile); myfile.close(); guestform(); greentext(); cout << "\tdetails have been saved\n\n\t"; whitetext(); system ("pause"); } } //} } }
i tried calling savefile function, gave same results. know it's creating new file of same data, except (in case) guest's name.
Comments
Post a Comment