fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <locale>
  5. #include <map>
  6.  
  7. std::string trim(std::string str) {
  8. while (!str.empty() && std::isspace(str[str.size()-1])) {
  9. str.resize(str.size()-1);
  10. }
  11. while (!str.empty() && std::isspace(str[0])) {
  12. str.erase(str.begin());
  13. }
  14. return str;
  15. }
  16.  
  17. int main() {
  18. typedef std::map<std::string, std::string> keyvalue_t;
  19. typedef std::map<std::string, keyvalue_t> data_t;
  20. data_t data;
  21.  
  22. //std::ifstream input("file.ini");
  23. std::istream& input = std::cin; // use above line for real code
  24.  
  25. std::string line, section;
  26. while (std::getline(input, line)) {
  27. line = trim(line);
  28. if (line.empty()) {
  29. continue;
  30. }
  31. if (line[0] == '[') {
  32. section = line.substr(1, line.size()-2);
  33. continue;
  34. }
  35. size_t eqpos = line.find('=');
  36. if (eqpos == std::string::npos) {
  37. data[section][line];
  38. continue;
  39. }
  40. std::string key = trim(line.substr(0, eqpos)), value = trim(line.substr(eqpos+1));
  41. data[section][key] = value;
  42. }
  43.  
  44. for (data_t::const_iterator section = data.begin() ; section != data.end() ; ++section) {
  45. std::cout << '[' << section->first << "]\n";
  46. for (keyvalue_t::const_iterator key = section->second.begin() ; key != section->second.end() ; ++key) {
  47. std::cout << key->first << '=' << key->second << '\n';
  48. }
  49. std::cout << '\n';
  50. }
  51. }
  52.  
Success #stdin #stdout 0s 3032KB
stdin
[Settings]
Treepos  =  3611.557861 2473.824219 8.986277
TreeSeed =654
 
[Animations]
Idle= idle
Running=run
Sprinting=run
Falling=fall
Jumping=fall
Swimming=fall
Floating=idle
Flying=idle
 
 [Avatar]
CameraDistance=11.00
Angle=76.000000 0.000000 73.199890
 Position=7806.417969 4053.380615 -0.217506
Flying=0
MouseSensitivity=1.00
InvertY=1
 
[Shaders]
ShaderNormal=standard.cg
ShaderTrees=trees.cg
stdout
[Animations]
Falling=fall
Floating=idle
Flying=idle
Idle=idle
Jumping=fall
Running=run
Sprinting=run
Swimming=fall

[Avatar]
Angle=76.000000 0.000000 73.199890
CameraDistance=11.00
Flying=0
InvertY=1
MouseSensitivity=1.00
Position=7806.417969 4053.380615 -0.217506

[Settings]
TreeSeed=654
Treepos=3611.557861 2473.824219 8.986277

[Shaders]
ShaderNormal=standard.cg
ShaderTrees=trees.cg