File I/O

Hello Everyone

I've been struggling to figure out what I'm sure is a simple problem. Say for example I'm creating a file that lists a description of a person, i.e. age, gender, weight.
int age = 40;
char gender = male;
int weight = 175;

and if i were to put that into a file called Barney.txt, the file would display this:

40
male
175

now i understand the basics of reading a file, but say i open the file and only want to read the gender (in this case 'male'). How do i go through reading a file only selecting certain chunks? All of the tutorials I have read only tend to confuse me more. Any help would be appreciated thanks.
You have to read (or explicity skip) everthing. A flat file has sequential access.
so there is no way to read the gender variable without first reading the age variable (In my example)?
You can ignore all the data before the newline character
eg:
1
2
yourfile.ignore(numeric_limits<streamsize>::max(),'\n');//Ignore everything before the 1st '\n'
yourfile >> gender;
Topic archived. No new replies allowed.