I have a text file containing a bunch of data which is actually a student list.
The structure is like: "Name" "Telephone" "Gender" "StudentID" "Email"
Here is a sample of the list:
Roger Pont 70778745 M 20120345 hills@school.edu
Tommy Holness 5127438973 M 20120212 tommy@school.edu
Lee Kin Fong 864564456434 F 30245678 fong@school.edu
The data is stored in a text file and I have already used the getline() function to convert each line into a string.
That is: student[0] contains "Roger Pont 7077874567 M 20120345 hills@school.edu"
My task is to sort the records according to StudentID in ascending order.
My problem is that I wanted to split the strings into different variable types.
However, since some names have more spaces in between and telephone number consists of different lengths, I can't use input and output streams is this way:
stream >> name[i] >> tel[i] >> gender[i] >> StudentID[i] >> email[i];
Any ideas how I can split the strings into different variables?
Thanks in advance.
Remarks: I have read this (Splitting a string into multiple variables in C++) but unlike that case, I don't have a specific pattern such as having the word "age" before the integer that represents age.