I've done something similar recently.
This is how I did it...
1. Read each line as a string into a vector.
This is easy. This can be done using getline(cin,string), then vector.push_back().
2. Read the first word of each line.
This isn't difficult either. Just check if the first word is something you recognise.
Code:
stringstream ss( line ); // include <sstream>
string firstWord ;
if ( (ss >> firstWord) ) {
// see if word is something you recognise
}
else {
// there are no words on this line; ignore
}
3. If the first word is something you recognise, read the rest of the line into values.
Code:
if ( firstWord == "HP" ) {
int hp ;
if ( ss >> hp ) {
// we got the health points
}
else {
// error
}
My suggestion is not to use =, : or any other characters to delimit strings. Just use spaces.
Code:
HP 400
MP 300
Stat Points 5
Location 2 2
Hope that helps.