Reading Specific Parts of a Text File

I am trying to read user setting from a file and need to be able to read the name and the settings.

The text file layout would be like this UserName set1,set2,set3,set4,set5
Example File:
Bill 50,10,10,20,10
Mike 25,25,5,15,30

What i would like to be able to do is set an int array to the values of the profile that was selected.



1
2
3
4
//  Example: Mike is selected
       for(int i=0; i<5; i++){
           settings[i] = *number from file*
       }


I was thinking i could use string::find or maybe strcmp as i found those from other posts but i am unsure if either of those are what i am looking for.

Any help would be appreciated.
scan each string delimited by a space into some string variable str
if str == "mike", scan the next 5 as integers to the array.
So it would be along the lines of this?

1
2
3
4
5
6
7
while ( getline (myfile,str, ' ') ){	
    if(str == "mike"){
        for(int i=0; i<5; i++){
	    settings[i] = str;
	}
    }    
}
Thats the idea but you messed up a little in line 4.
You will be filling settings with "mike".
after line 2, you will scan 5 integers from the file to settings.
Last edited on
good point so it would have to be more like this.


1
2
3
4
5
6
7
8
while ( getline (myfile,str, ' ') ){	
    if(str == "mike"){
        for(int i=0; i<5; i++){
	    getline (myfile,temp, ' ');
            settings[i] = temp;
	}
    }    
}
Topic archived. No new replies allowed.