Guest User

Untitled

a guest
Feb 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <pcrecpp.h>
  3. #include <string>
  4. #include <map>
  5. #include <fstream>
  6.  
  7. #define LINE_SIZE 256
  8.  
  9. typedef std::map<std::string,std::string> Hash;
  10.  
  11. int main(int argc,char** argv){
  12.  
  13. if(argc != 2)
  14. {
  15. std::cout<<"Usage: configlol <configfile>"<<std::endl;
  16. return -1;
  17. }
  18.  
  19. std::string filename(argv[1]);
  20.  
  21. std::fstream file(filename.c_str());
  22.  
  23. std::string var, val;
  24. pcrecpp::RE re("(\\w+):\\s+(.+)");
  25.  
  26. Hash config;
  27.  
  28. while( !file.eof() ){
  29.  
  30. char line[LINE_SIZE] = "" ;
  31.  
  32. file.getline(line,LINE_SIZE);
  33.  
  34. re.FullMatch( line , &var, &val);
  35.  
  36. config[var] = val ;
  37.  
  38. }
  39.  
  40. // config["name"]
  41.  
  42. for(Hash::iterator p = config.begin() ; p != config.end(); p++)
  43. {
  44. std::cout << p->first << " : " << p->second << std::endl;
  45. }
  46.  
  47.  
  48. return 1;
  49. }
Add Comment
Please, Sign In to add comment