Loading text from file into struct

This is a discussion on Loading text from file into struct within the C++ Programming forums, part of the General Programming Boards category; I was hoping someone could give me a hand or point me in the right direction
I have a text ...

Ok your on the right track using find and substr methods of the string class. I would say that you should do something kinda like this :

Code:

vector<string> file;
....
....
person a_person;
vector<person>
while(int i < file.size())
{ int iCommaPos1 = file[i].find(",");
// or alternitively you could manually search by using a loop
a_person.first = file[i].substr(0,iCommaPos);
int iCommaPos2 = file[i].find(",",iCommaPos1+1); // tells it to
// searching from right after the last comma
a_person.last = file[i].substr(iCommaPos1+1,(iCommaPos2-iCommaPos1)); // this is because the length of this substr is the
// difference between the two positions
int iCommaPos3 = file[i].find(",",iCommaPos2+1);
a_person.age = file[i].substr(iCommaPos2+1,(iCommaPos3-iCommaPos2));
if(iCommaPos3 < file[i].length())
{ int iCommaPosC = file[i].find(",",iCommaPos3+1);
if(iCommaPosC > file[i].length() || iCommaPosC < 0)
children.push_back(file[i].substr(iCommaPos3+1,(file[i].length() - iCommaPos3)));
else
{ chilldren.push_back(file[i].substr(iCommaPos3+1,(iCommaPosC - iCommaPos3)));
........
// repeat the test again to see if this is the last comma
// if searching for a nother fails, if so then your finished
// if not then you do another push_back like the one i used
// in the else, this code might not be perfect you might
// have to adjust the substr's a little its been a while
// since ive done this