I am going to be parsing a log file from a game to determin how many times a person casted the same spell. I don't know though, how to store data on a thing without first making a variable for it. I have this so far:
I know inline voids aren't most peoples favorite, but that is what I used for this first version, later versions will probably need complete rewrites to make it faster anyway.Code:#include <iostream> #include <fstream> #include <string> using namespace std; inline void loadfile(ifstream& file) { file.open("eqlog_Brahman_povar.txt"); int attempt = 1; while(attempt==1) { if (!file.is_open()) { string filename; cout<<"Please specify the name, and possibly"<<endl <<"the path to the EQ log."<<endl; getline(cin,filename); file.open(filename.c_str()); } if (!file.is_open()) { cout<<"The file does not appear to be there!"<<endl <<"If you wish to try again, please press enter 1."<<endl <<"Press any other key to exit the program and give up."; cin>>attempt; } else { cout<<"The file is open!"; attempt = 0; } } } inline void counter(ifstream& file) { int datestamp = 27; int count = 0; string line; while (getline( file , line )) { int read_pos = line.find("begins",0); int spell_pos = line.find("<",0); if(read_pos>0 && spell_pos>0) { string caster = line.substr(datestamp,read_pos-datestamp); cout<<"Caster:"<<caster; string spell = line.substr(spell_pos+1,line.size()-spell_pos-2); cout<<" Spell: "<< spell<<endl; count++; } } cout<<"Spells casted: "<<count; } int main() { ifstream file; loadfile(file); counter(file); cin.get(); }
~Wraith



LinkBack URL
About LinkBacks


