I'm trying to parse an INI file using C++. Any tips on what is the best way to achieve this? Should I use the Windows API tools for INI file processing (with which I am totally unfamiliar), an open-source solution or attempt to parse it manually?

+8  A: 

I have never parsed ini files, so I can't be too specific on this issue.
But i have one advice:
Don't reinvent the wheel as long as an existing one meets your requirements

Good luck :)

Lars Mæhlum
+3  A: 

Just use the Win32 APIs. Don't worry, they're easy as pie.

+50  A: 

You can use the Windows API functions, such as GetPrivateProfileString() and GetPrivateProfileInt().

Joel Spolsky
+2  A: 

Unless you plan on making the app cross-platform, using the Windows API calls would be the best way to go. Just ignore the note in the API documentation about being provided only for 16-bit app compatibility.

+19  A: 

If you need a cross-platform solution, try Boost's Program Options library.

Adam Mitz
i would suggest this library too
this is the way to go, I don't understand why people just up-vote not-so-general answer.
+3  A: 

I use SimpleIni. It's cross-platform.

Harold Ekstrom
+3  A: 

Have you tried libconfig; very JSON-like syntax. I prefer it over XML configuration files.


google sscanf or fscanf

+2  A: 

this question is a bit old, but I will post my answer. I have tested various INI classes (you can see them on my website) and I also use simpleIni because I want to work with INI files on both windows and winCE. Window's GetPrivateProfileString() works only with the registry on winCE.

It is very easy to read with simpleIni. Here is an example:

#include "SimpleIni\SimpleIni.h"    
CSimpleIniA ini;
const char * pVal = ini.GetValue(section, entry, DefaultStr);