Not sure what I am doing wrong(File IO)

Basically, what happans is that the save works perfect, just that when it loads, it just outputs to screen and not into where i had wanted them to go. Also when reading the places that they should go, they have very off numbers, that are not what they were supposed to be.....
Can add code of the actual classes if needed.
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
27
28
29
30
31
32
33
void db::save(){
	ofstream myfile (name.c_str(), ios::out| ios::trunc);
	myfile<<name;
	for(int x=0;x<30;x++){
		myfile<<group[x].name;
	myfile<<group[x].emonth();
	myfile<<group[x].eday();
	myfile<<group[x].eyear();
	for(int y=0;y<3;y++){
		myfile<<group[x].elockercom(y);}
	}
	myfile.close();}

void db::load(){
	string nname;
	getline(cin,nname);
	ifstream myfile (nname.c_str(),  ios_base::in);
myfile>>name;
	for(int x=0;x<30;x++){
		myfile>>group[x].name;
	myfile>> group[x].locker;
	short int month, day, year;
		group[x].edmonth(myfile.get());
	myfile>>day;
	group[x].edday(day);
	myfile>>year;
	group[x].edyear(year);
	for(int y=0;y<3;y++){
		int z;
		myfile>>z;
			group[x].edlockercom(y,z);}
	}
	myfile.close();} 
Are you sure the save is working perfectly? You're not putting any whitespace between each number.
I am pretty sure the save is fine, because when I looked into it, it had everything with no gaps, and also, it outputted everything to the console screen fine.
What helios means is that you will not be able to extract individual value out of the file because there is no space or newline between the values.

The program will grab the entire line and place that in one variable.
Topic archived. No new replies allowed.