#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void displayStudents(string [], int [], int);

int main()
{
	const int SIZE = 5;
	string name;
	string names[SIZE];
	int age;
	int ages[SIZE];
	fstream infile("students.txt", ios::in);
	
	cout << "Reading from students.txt - start" << endl << endl;
	for (int i=0; i<SIZE; i++) {
		
		//read name from students.txt
		cout << "Reading name from students.txt - ";
		infile >> name;
		cout << name << endl;
		
		//read age from students.txt
		cout << "Reading age from students.txt - ";
		infile >> age;
		cout << age << endl << endl;	
		
		//add to array names and ages
		names[i] = name;
		ages[i] = age;
	}
	cout << "Reading from students.txt - end" << endl << endl;
	
	cout << "Printing student name and age from array" << endl << endl;
	displayStudents(names, ages, SIZE);
	
	infile.close();
	
	return 0;
}

void displayStudents(string names[], int ages[], int size) {
	
	for (int i=0; i<size; i++) {
		cout << "Student [" << i+1 << "] name:" << names[i] << endl;
		cout << "Student [" << i+1 << "] age:" << ages[i] << endl;
		cout << endl;
	}
}
