crashing out?

I have a binary file that has 1000 null versions of a strct called customerInfo that looks like this
1
2
3
4
5
6
7
8
9
struct customerInfo
{
	string user;
	string pass;
	string credit;
	string mail;
	string movieOut;
	bool oneOut;
};


My goal as of right now is to pull out one customer by comparing the user name and password, called user and pass respectively. I have figured out a way to write to the file so as not to overwrite already existing users and to prevent people from having the same user name. However when I try to pull out one user using this bit of code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
	std::fstream customerData;
	customerData.open("customerData.dat",ios::in|ios::binary);
	if(customerData.fail())
	{
		cout<<"Cannot connect to customer data right now\n";
		system("pause");
	}
	customerData.seekg(0L,ios::beg);
	customerData.seekp(0L,ios::beg);
	for(int temp=0;temp<1000;temp++)
	{
		customerData.read((char*)&gatherd,sizeof(customerInfo));
		if((gatherd.user==userName)&&(gatherd.pass==password))
		{
			temp=1001;
			customer.credit=gatherd.credit;
			customer.mail=gatherd.mail;
			customer.movieOut=gatherd.movieOut;
			customer.oneOut=gatherd.oneOut;
		}
//Just after the if statement is where it crashes.
	}
	cout<<"Welcome "<<gatherd.user<<"!\n";
	system("pause");
	customerData.close();
}


...It crashes at the same spot every time. Just after the if statement. The program compiles fine. userName and password are of type string and are taken in by the function. Any help would be greatly appreciated! I've been at this for to long now and the program is due in...two hours ago :0!

P.S. gatherd is of type customerInfo as is customer.
Last edited on
the problem is the string members of your struct.

I hope this helps
http://cplusplus.com/forum/beginner/23163/#msg121662
maybe I'm missing it. The other post they are having the same kind of problem but I don't seem to understand the solution.
It uses c-string instead of std::string.
Topic archived. No new replies allowed.