Getting the cross-platform path for the configuration file (C / C ++)

I would like to save my application settings in a configuration file. On Linux (and Mac?) It (maybe) will be /home/user/.config/app.conf, and on Windows it will be (C): C: \ Documents and Settings \ username \ Application Data \ app.conf ". Of course , it can be saved elsewhere, so the only way to get the right location is to use a platform-specific function.

Suffice it to say that I do not want to risk coding this myself and make mistakes (because I do not have access to some of these platforms for testing), and does anyone know if there is any well-tested C / C + cross-platform + who can do this? A .h / .hpp file that uses a bunch of #defines will also be great if it is used widely.

I thought that the Boost program options library might (since it can load configuration files), but it doesn't seem capable.

Any suggestions?

+7
source share
3 answers

This reappeared, so I decided to bite the bullet and create my own solution, since only the existing ones are part of huge frameworks and are impractical for small programs.

I posted the code at https://github.com/Malvineous/cfgpath

It is placed in the public domain, so it can be used by any user for any purpose. It has no dependencies outside of the standard platform APIs. Just #include one .h file and call one of the functions. Other files in the repository are just a test code, you do not need this data if you do not want to make the changes that you intend to send to me (please do it!)

Unfortunately, as I said in my original post, I do not have easy access to many platforms, so I hope that I will get some patches to add support for more platforms.

+3
source

The Qt QSettings class will do this for you.

On * nix settings will be saved in $ HOME / .config. In Windows, the settings will be saved in the registry. On Mac, the settings will be saved in $ HOME / Library / Preferences /.

+3
source

I think help increase file system libraries . It has platform-independent grammar paths.

0
source

All Articles