Hello all I've been at this for a good long 4 hours now and see nothing wrong with my code...I am still a bit of a newbie so any help would be appreciated.
struct customerInfo
{
string user;
string pass;
string credit;
string mail;
string movieOut;
bool oneOut;
};
customerInfo nCustomer;
NewCustomer::NewCustomer(string userName,string password,string checkPassword,string creditCard,string eMail)
{
nCustomer.user=userName;
nCustomer.pass=password;
while(nCustomer.pass!=checkPassword)
{
system("cls");
cout<<"Your passwords do not match please re-enter the password\n"
<<"password: ";
getline(cin,nCustomer.pass);
cout<<endl;
cout<<"Please re-enter your password\n"
<<"password: ";
getline(cin,checkPassword);
}
nCustomer.credit=creditCard;
nCustomer.mail=eMail;
nCustomer.oneOut=false;
}
void addToDataBase()
{
ofstream inFile ("customerData.dat",ios::app|ios::binary);
if (!inFile.fail())
{
cout<<"cannot write to file\n"
<<endl;
system("pause");
inFile.close();
}
else
{
inFile.seekp((long)0,ios::beg);
int count=1;
while(!inFile.eof())
{
inFile.seekp((long (sizeof (customerInfo))*count),ios::beg);
count++;
}
inFile.write((char*)&nCustomer,sizeof (customerInfo));
inFile.close();
cout<<"Welcome to Joe's DVD Shed!\n";
}
}
This is the code i have so far in a class called NewCustomer, when i compile it with out the addToDataBase method it compiles fine so I know the problem is in there this is my first program saving to a binary file so i'm pretty sure thats what i'm doing wrong.
So what happens when you run the program? Does it crash or something? Does customerInfo a class? Maybe it contains string object that cause it to fail.