Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <pcrecpp.h>
- #include <string>
- #include <map>
- #include <fstream>
- #define LINE_SIZE 256
- typedef std::map<std::string,std::string> Hash;
- int main(int argc,char** argv){
- if(argc != 2)
- {
- std::cout<<"Usage: configlol <configfile>"<<std::endl;
- return -1;
- }
- std::string filename(argv[1]);
- std::fstream file(filename.c_str());
- std::string var, val;
- pcrecpp::RE re("(\\w+):\\s+(.+)");
- Hash config;
- while( !file.eof() ){
- char line[LINE_SIZE] = "" ;
- file.getline(line,LINE_SIZE);
- re.FullMatch( line , &var, &val);
- config[var] = val ;
- }
- // config["name"]
- for(Hash::iterator p = config.begin() ; p != config.end(); p++)
- {
- std::cout << p->first << " : " << p->second << std::endl;
- }
- return 1;
- }
Add Comment
Please, Sign In to add comment