Trying to read from a text file with format:
Jamie 27 31
Tom 31 22
Rashid 22 19
Sarah 18 22
Ricardo 90 27
I want to separate this into three vectors, <name>
, <x>
and <y>
:
ifstream in ("data.txt");
vector<string> names;
string name;
if (!in)
return;
while (in >> name)
names.push_back(name);
And then the same for x
and y
but with vector<int>
.
As it stands this code will read all words into names
and treat them like strings. I need to do some maths on x
and y
so I need them as type int.
I was thinking of using multiples but I'm sure there is a more elegant solution. As in, y
will always have an index completely divisible by three once read into names
, providing I create an empty first position in names[0]
. Can anybody help me out?
KR