ifstream garbage from good file

Hello. I successfuly write my file but the reading gives the output below. My code is

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
if(readFile.is_open() && readFile.good()){
			cout<<"File exists and ready to be read!"<<endl;
			readFile>>noskipws;
			cout<<endl;
			readFile.ignore(10,'\n');//ignore first line of file
			//read in to struct variable info from file
			for(int i=0;i<numberRec;i++){//size of array of struct
				readFile.getline(info[i].name,100);
				
				readFile.getline(info[i].about,100);	
				
				readFile.getline(fileread,100);	
				info[i].items=atoi(fileread);
				
				readFile.getline(fileread,100);	
				info[i].price_per_item=atoi(fileread);
				
				readFile.getline(info[i].details.name,100);	
				
				readFile.getline(info[i].details.address,100);
					
				readFile.getline(info[i].details.phone,100);
					
			
		}
		
	readFile.clear();
	readFile.ignore();
	readFile.close();
	
	}


		Welcome to Karim & Co. Chocolate Store

do you wish to create a file for chocolates?
N
Enter file to open: choco.txt
Please enter number of records to read: 2
File exists and ready to be read!

Please choose from main menu
		1.Sales Transaction 2.Restock Chocolate
		3.Change Supplier Info 4.Display Chocolate Info
		5.Quit
Choose from main menu?: 
4
Type 1

2
ش
0
0
0

ύ�
Type 2



0
0


display struct info function is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void displayInfo(chocolate info[100], int number){
	
	for(int i=0;i<number;i++){
			cout<<"Type "<<i+1<<endl;
			cout<<endl;
			cout<<info[i].name<<endl;
			cout<<info[i].about<<endl;
			cout<<info[i].items<<endl;
			cout<<info[i].price_per_item<<endl;
			cout<<info[i].details.name<<endl;
			cout<<info[i].details.address<<endl;
			cout<<info[i].details.phone<<endl;
			}
	}


Show your save function and content of file
Topic archived. No new replies allowed.