Is there a special place to store configurations in standard c++
Is there a standard place to store configurations like database setting in c++? Just use xml file?
Need windows solution, but it is better to be pla开发者_Python百科tform independent.
Check out Boost Program Options. Apart from being one of the best command-line option processors in any language, it also supports reading configuration data from files with a syntax like INI, and using environment variables. It's suitable for exactly what it says: program options. If you have a huge variety or a hierarchy of configurations, however, you might better check out Boost Property Tree, which read INI files but also XML or JSON, and is probably better suited if you have a really large configuration.
No standard that I know of, but you have several libraries for program configuration, for example libconfig. Also, the Windows API has some utilities to parse INI files for programs, for example see this link.
Standard C++ is a language only, it don't know anything other than the language itself.
What you're asking totally depends on the libraries or framework you'll decide to use to connect to databases. There is no standard library that have this purpose. So first choose the database, then the library to connect to it, then you'll get the configuration infos in the library documentation.
There's nothing in the standard, but Boost.Program_options is a good library for retrieving/storing configuration.
Obviously the configuration file must be stored in the correct location: if it's a per-user configuration file, on Windows it will be stored in the %APPDATA%
1 directory (usually in a subdirectory named after your application), on Linux in a dot file under the home directory. For non-user specific configuration files, they may be stored in the "All Users" Application Data folder on Windows1, and under /etc on Linux2.
Naturally, you won't hardcode these paths, but you'll use SHGetFolderPath with the appropriate CSIDL values (or SHGetKnownFolderPath if you don't care about pre-Vista compatibility), like
CSIDL_APPDATA
for per-user settings,CSIDL_COMMON_APPDATA
for settings common to all users.Notice that
/etc
on Linux is writeable only by the superuser; I don't remember if the "all users" profile is writable for normal users under Windows.
精彩评论