fstream reservationFile; //creating output stream file to write reservation input
reservationFile.open("reservationLog.txt");
(ios::app);
if(reservationFile.fail()){
cout<<"File reservation unsuccessfully opened."<<endl
<<"Please check to see if file exists."<<endl;
exit(1);
}
int main(){
int bookName;
int currentDate;
int startDate;
int lengthStay;
cout<<"Please enter book name:"<<endl; //enter book name
cin>>bookName;
reservationFile<<bookName; //write book name to reservationFile file
cout<<endl<<"please enter toady's date(yyyymmdd):"<<endl; //enter current date
cin>>currentDate;
reservationFile<<currentDate; //write current date to reservationfile
cout<<endl<<"please enter start date:(yyyymmdd)"<<endl; //enter start date
cin>>startDate;
reservationFile<<startDate; //write start date to reservationfile
cout<<"Please enter length of stay:"<<endl; //enter length of stay
cin>>lengthStay;
reservationFile<<lengthStay; //write length of stay to reservation file
cout<<"Welcome to the edit booking menu!"<<endl
<<"select booking"<<endl;
cin>>bookName;
cout<<reservationFile;
}
I need to get to bed and take my last final in the morning but I noticed you are using an fstream so I take it that you want to both read and write through it.
I am not positive on this but I believe that it is automatically set to be an input filestream only so you might have to enable both by using:
Ok, so I took some time and browsed this site and I can show you 95% of the way. This code will find the bookname and overwrite it but it will only work perfectly if the number of characters are the same. So I guess it's up to you to figure out how to make it work for different sized booknames. You can do it guy, I have faith in you!