looping in array with class names

Sep 28, 2016 at 11:58pm
I'm trying to use a loop to load an array from a file with strings and ints. Additionally while it is loading into the array I would like it to set the class names. So I can call it to output with a different function. I think the rest of my program is working but I always struggle with loops.

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 loadData(President pres_array[], const int SIZE,
						int count)
{
	fstream inFile;
	inFile.open("prez_data", ios::in);
	
	string 	first,
		last,
		party;
	int	begin,
		end,
		temp;

	while (!inFile.eof() && count < SIZE)
	{
		getline(inFile, first);
		pres_array[temp].setFirstName(first);
		getline(inFile, last);
		pres_array[temp].setLastName(last);
		inFile >> begin;
		pres_array[temp].setBeginYear(begin);
		inFile >> end;
		pres_array[temp].setEndYear(end);
		inFile.ignore();
		getline(inFile, party);
		pres_array[temp].setPartyAffil(party);
	
		system("pause");
		displayPresident(temp);
		++count;
	}
	inFile.close();
}


Any help would be awesome.
Sep 29, 2016 at 12:00am
What are the contents of your input file?
Sep 29, 2016 at 12:10am
line of string (first name)
line of string (last name)
int (year)
int (year)
line of string (party affiliation)
(that pattern repeats 17 times)

the reason I need to use getline for the string lines some times first, last, and party more than one word
Topic archived. No new replies allowed.