Multiple words from file into one string - structures

Apr 8, 2013 at 4:16pm
So i have a file that reads: Name, Mobile number, Gender, age

e.g. Sarah Megan 12345678 F 19
John F Dan 12345678 M 23
Paul 12345678 M 34

by using structures if the name was only one word i guess i can use
1
2
3
4
5
6
string name;
int mobile;
char gender;
int age;

cin >> name >> mobile >> gender >> age


but how would you put two or three worded names into a string?

Thank you in advance.
Last edited on Apr 8, 2013 at 5:46pm
Apr 8, 2013 at 10:40pm
You would have to find a different way to tell apart different information in the file. Either the name has to come last so that you know the rest of the line is the name, or you need to separate things with commas so the name is the only thing with spaces.

As a last resort, you could find out how many space separated words there are and you know that the last 3 are not the name.
Last edited on Apr 8, 2013 at 10:41pm
Topic archived. No new replies allowed.