Reading from a text file into Parallel Arrays

Having trouble reading information from a text file to parallel arrays. The info is arranged as such in the file:


Name
Street Address
City, State, Zip
Order size

Name
Street Address
City, State, Zip
Order size


Basically I need to pull the names, street address, and city/state/zip as lines into string arrays and then pull the order size into an int array to do some calculations. Grand total of 4 arrays.

Problem is it'll read the first order just fine, but the second order looks like


John Doe
123
Main Street
City, State Zipcode
9
0
9
9
4679937
9
0
9
9
4710208



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
        const int ORDERS = 10;
        cout << "Reading from file..." << endl;
	ifstream inputFile;
	
	string name[ORDERS], streetAddress[ORDERS], cityStateZip[ORDERS];
	string line;
	int orderSize[ORDERS];
	
	inputFile.open("Orders.txt");
	for(int i = 0; i < ORDERS; i++)
	{	
		getline(inputFile, line);
		name[i] = line;
		getline(inputFile, line);
		streetAddress[i] = line;
		getline(inputFile, line);
		cityStateZip[i] = line;
		inputFile >> orderSize[i];	
	}
	
	inputFile.close();
	
	for(int i = 0; i < ORDERS; i++)
	{
		cout << name [i] << endl;
		cout << streetAddress[i] << endl;
		cout << cityStateZip[i] << endl;
		cout << orderSize [i] << endl;
	}


Any ideas? Seems like it's trying to read the strings as ints after the first order or something.
Last edited on
Actually got this figured out on Stack. The solution is to use getline 5x (4 with data, one blank) and then convert the 4th string into an int for calculations.

I'll leave this here in case anyone has a similar problem.
Topic archived. No new replies allowed.