Get rid of the spaces. Extract the first element of the string. That's your prefix. Then the rest of the string needs to be converted to a number. Stringstreams are useful for this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Read file till EOF
while(data >> stuff){
char prefix = stuff[0];
string number(stuff.begin()+1, stuff.end());
stringstream iss(number);
int in;
iss >> in;
if(prefix == 'i'){
cout << "I = " << in << endl;;
}
// If "d" is encountered
elseif(prefix == 'd'){
cout << "D = " << in << endl;
}
data.clear();
}
stuff = "i1"
prefix = 'i'
number = "1" Now we need to convert it to a number
stick it in a stream
in = 1