I'm writing a program that takes in a file in the format:
id number
name
address
phone number
The input file will repeat this set of four lines an unspecified number of times. I have a class with a member variable for each item and I want to put each instance of the class into a vector. I'm struggling to come up with a way to put each line into a different variable(int, string, string, string) and then keep repeating that for every four lines. My first idea was to use a stringstream but I couldn't get anywhere with that.
I use this to read in each line in the file.
1 2 3
while (getline(studentFile,line)) {
}
Can anyone give me some ideas to work with? Thanks for your help!
If you are able to change the format to something like: "id number,name,address,phone number" you could then use getline() to read the entire line, then use a stringstream to parse this line.