- Joined
- Dec 8, 2008
Hey,
I'm writing a simple log parser to track /rolls in LotRO. It's a fairly straightforward application, it reads in lines from the input file as a string, and checks it for the player name, and the keyword " rolled (100)". I am having trouble pulling the integer from the end of the string. The format of the line is always as follows:
(using my main toons name)
I have tried tokenizing, as well as a stringstream, but I find they either don't work or I don't fully understand the proper method of implementation. If it's helpful, here's a portion of the code:
Can somebody give me some tips on reading integers from strings?
Thanks in advance
I'm writing a simple log parser to track /rolls in LotRO. It's a fairly straightforward application, it reads in lines from the input file as a string, and checks it for the player name, and the keyword " rolled (100)". I am having trouble pulling the integer from the end of the string. The format of the line is always as follows:
(using my main toons name)
Code:
Falthelion rolled (100): 34
I have tried tokenizing, as well as a stringstream, but I find they either don't work or I don't fully understand the proper method of implementation. If it's helpful, here's a portion of the code:
Code:
void readRoll(string file, string charName, string saveFile){
int rollTotal=0, numRoll=0, rollAvg=0, roll=0;
ifstream OpenFile(file.c_str()); // open up the log file for parsing
ofstream SaveFile(saveFile.c_str(),ios::app); // open up the data file in append mode, so that we don't overwrite any existing data.
string line; //string variable we will use for parsing
while(!OpenFile.eof()){ //loop through file until EOF character is reached.
getline(OpenFile,line,'\n');
if(line.find(charName + " rolled (100)") != string::npos){//if character name is in line, write to console AND file.
cout << line << endl;
numRoll++;
if(!SaveFile.is_open()){ //make sure that the SaveFile is open, exit if it is not.
cout << "Error! " << saveFile << " could not be opened!" << endl;
}else{
SaveFile << line << endl; //write line to the file.
}
}else if(line.find("rolled (100)") != string::npos){ //if character name isn't in the line, write to file, but not console.
if(!SaveFile.is_open()){ //make sure that the SaveFile is open, exit if it is not.
cout << "Error! " << saveFile << " could not be opened!" << endl;
}else{
SaveFile << line << endl;
}
}
}
OpenFile.close();//close the files, just to be safe.
SaveFile.close();
}
Can somebody give me some tips on reading integers from strings?
Thanks in advance