I have a text file:
bob,10,20,30
joe,50,60,50
shelly,20,15,29
that I want to read into a vector of type student, defined:
class student
{
public:
string name;
int exam1;
int exam2;
int exam3;
student (string s, int x, int y, int z)
{
name = s;
exam1 = x;
exam2 = y;
exam3 = z;
}
};
Using iterators begin() and end(), I am able to store the strings, line by line, but I want to be able to parse these strings to store a students name and his/her exam scores, but I don't know it can be done.
I read about 'find' and 'substr' from the string class but I'm a bit new to iterators and vectors in general. How can I parse the vector using 'find' and 'substr' when it is of type ? I know there may already be many errors in my code or thinking.
main:
int main()
{
//Open file and create iterator
ifstream file ("test.txt");
istream_iterator<string> begin (file), end;
vector<student> vec (begin, end);
}