Hi everyone quick c++ question. I have a file that is formatted in a special way. The first line is a person's first and last name, the second line is his phone number and the third is adress. this a peace of the file, it's much larger but it looks like this:
Mans Hansson
8510309159
Bössgränd 90, 373 02 RAMDALA
Olliver Lindberg
8602024898
Sandviken 76, 710 27 DYLTABRUK
Eskil Johnsson7901105838
Löberöd 29, 521 29 KÄTTLISTORP
And basically I want to read the first three lines once at a time. What I mean is I want to read line one and store in a variable called name, line 2 in phone_number and line 3 in adress and then repeat until end of file. this is my code:
int main(){
    fstream fs; 
    fs.open("/Users/brah79/Downloads/skola/c++/OOP/uppgift1/personInfo.txt"); 
    string name; 
    string phone_number; 
    string adress;
    while(!fs.eof()){
       for(int i = 0; i < 3; i++){
        getline(fs, name); 
        getline(fs, phone_number); 
        getline(fs, adress); 
       }
       cout << "first name: " << name << endl; 
       cout << "person nummer: " << phone_number << endl; 
       cout << "adress: " << adress << endl; 
    }
    fs.close(); 
    return 0; 
}
this is the output:
first name: Eskil Johnsson
phone number: 7901105838
adress: Löberöd 29, 521 29 KÄTTLISTORP
question 1: my code is only reading the last three lines so basically information about the last person only.
question 2: the name of the person consists of first and last name and I could not figure out a way to separate them into 2 variables.
Hope my question is clear and someone can help.
 
     
    