What is the easiest way to parse an INI File in C++?

If you are already using Qt

QSettings my_settings("filename.ini", QSettings::IniFormat);

Then read a value

my_settings.value("GroupName/ValueName", <<DEFAULT_VAL>>).toInt()

There are a bunch of other converter that convert your INI values into both standard types and Qt types. See Qt documentation on QSettings for more information.


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


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


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

http://en.wikipedia.org/wiki/INI_file#Accessing_INI_files
http://sdl-cfg.sourceforge.net/
http://sourceforge.net/projects/libini/
http://www.codeproject.com/KB/files/config-file-parser.aspx

Good luck :)