Posted By

jimfred on 02/24/10


Tagged


Versions (?)

trivial example, C++, gcc, using simpleIni.h


 / Published in: C++
 

URL: http://code.google.com/p/simpleini

http://stackoverflow.com/questions/12633/what-is-the-easiest-way-to-parse-an-ini-file-in-c

  1. #include "SimpleIni.h"
  2. #include <stdio.h>
  3.  
  4. // Linux gcc compilation:
  5. // g++ -o test.exe test.cpp
  6. // gcc -o test.exe test.cpp -lstdc++
  7.  
  8. int main( int argc, char** argv)
  9. {
  10. CSimpleIniA ini;
  11.  
  12. ini.SetValue("section", "param", "123");
  13. ini.SaveFile("test.ini");
  14.  
  15. // Should result in file with contents:
  16. // [section]
  17. // param=123
  18.  
  19. ini.LoadFile("test.ini");
  20. const char * pVal = ini.GetValue("section", "param", "default");
  21.  
  22. printf( "value=%s", pVal ); // should print "value=123"
  23.  
  24. return 0;
  25.  
  26. }

Report this snippet  

You need to login to post a comment.