void New()
{
int idnumber;
int contact;
char name[100];
char country[100];
char street[100];
char parish[100];
char category[100];
char booking[100];
char idtype[100];
int lnumber;
char make[100];
char model[100];
char color[100];
char type[100];
char ans;
char ch[1];
cout<<"Please enter the guest information below";
fflush(stdin);
cout<<"\nEnter name:";
cin.getline(name,100);
fflush(stdin);
cout<<"Enter idnumber:";
cin>>idnumber;
fflush(stdin);
cout<<"Enter contact:";
cin>>contact;
fflush(stdin);
cout<<"Enter address line 1:";
cin.getline(street,100);
fflush(stdin);
cout<<"Enter address line 2:";
cin.getline(parish,100);
fflush(stdin);
cout<<"Enter address line 3:";
cin.getline(country,100);
fflush(stdin);
cout<<"Enter category:";
cin.getline(category,100);
fflush(stdin);
cout<<"Enter booking:";
cin.getline(booking,100);
fflush(stdin);
cout<<"Enter idtype:";
cin.getline(idtype,100);
cout<<"Does the customer have a vechile:";
cin>>&ans;
if(ans=='y'||ans=='Y')
{
fflush(stdin);
cout<<"\nEnter license number:";
cin>>lnumber;
fflush(stdin);
cout<<"Enter make:";
cin.getline(make,100);
fflush(stdin);
cout<<"Enter model:";
cin.getline(model,100);
fflush(stdin);
cout<<"Enter color:";
cin.getline(color,100);
fflush(stdin);
cout<<"Enter type:";
cin.getline(type,100);
vehicle now(lnumber,make ,model,color,type);
now.display();
}
guest info(idnumber,contact,name,street,parish,country,booking,category,idtype);
info.display();
ofstream file("guest.txt",ios::out);
file.open(reinterpret_cast<char *>(&guest),sizeof(info);
file.close();
cout<<"\n";
system("pause");
}
Writing an object to file{help}
Started by hbk, Oct 29 2010 05:30 PM
1 reply to this topic
#1
Posted 29 October 2010 - 05:30 PM
I ahve the below code but the problem is that it creates the file but it is empty
|
|
|
#2
Posted 02 January 2011 - 12:08 PM
Try replace this
Infinity
ofstream file("guest.txt",ios::out);
ofstream file ("guest.bin", ios::out | ios::app | ios::binary);
And see this: Input/Output with filesInfinity
Edited by Infinity, 03 January 2011 - 09:06 AM.


Sign In
Create Account


Back to top









