Help with vectors!!

Hi guys, I really need help. I need to print in the screen from my file input.txt the students names, their grades, and calculate the highest grade and lowest grade for each student. Also the average.
This is what I have done, but I am stuck on how to read the names like string and a numbers like integer, so i could work with numbers for the calculations.

#include <vector>
#include <iostream>
#include <fstream>

using namespace std;

int main () {
vector<string>names;
string line;
ifstream myFile ("input.txt");


if (myFile.is_open())
{
while (getline (myFile,line) )
{
string new_line;
new_line = line + "\n";
cout<<new_line;
names.push_back(new_line);

}

myFile.close();
}

else cout << "Error";

return 0;
}

My input.txt file looks like this:

Mark G Creek 78 45 98
John F Gok 78 93 98
Louis L Gik 100 45 80
Mark G Creek 78 45 98

Could you tell me what the numbers 78, 45, 98 mean?
Surely they may be grades, you need to be a little bit more specific about it.

Krulcifer Einfolk
It could be like this:
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <vector>
#include <iostream>
#include <fstream>
#include <array>
#include <string>

struct student
{
	std::string name;
	std::array<int, 3> grades;

	int get_lowest_grade() const
	{
		return *std::min_element(grades.begin(), grades.end());
	}

	int get_highest_grade() const
	{
		return *std::max_element(grades.begin(), grades.end());
	}
};

int main()
{
	std::vector<student> students;

	try
	{
		std::ifstream myFile("input.txt");
		if (myFile.is_open())
		{
			std::string line;
			while (std::getline(myFile, line))
			{
				std::cout << line << std::endl;

				student stud;
				// fields separated by space: name grade0 grade1 grade2
				// name can contain spaces, so last 3 substrings are grades
				size_t end = line.size() - 1;
				for (int i = stud.grades.size() - 1; i >= 0; --i)
				{
					size_t begin = line.rfind(' ', end);
					if (begin == line.npos)
					{
						throw std::exception("grade not found");
					}

					// substring containg the grade
					std::string str = line.substr(begin + 1, end - begin);
					stud.grades[i] = std::stoi(str);

					// set new end
					end = begin - 1;
				}

				// remaining text is the name
				stud.name = line.substr(0, end + 1);

				// add to list
				students.push_back(stud);
			}

			myFile.close();

			// show students
			std::cout << "---------------------------------" << std::endl;
			for (auto it = students.begin(); it != students.end(); ++it)
			{
				const student& stud = *it;
				std::cout << "Name: " << stud.name
					<< ", highest grade: " << stud.get_highest_grade()
					<< ", lowest grade: " << stud.get_lowest_grade()
					<< std::endl
					;
			}
		}
		else
		{
			throw std::exception("error opening file");
		}
	}
	catch (const std::exception& ex)
	{
		std::cout << "Error: " << ex.what();
	}

	return 0;
}

If there are functions that you don't know you can check their documentation.
Topic archived. No new replies allowed.