C++ Linux 配置文件库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/147902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:13:53  来源:igfitidea点击:

Linux configuration file libraries

c++clinuxconfigurationfile

提问by jcodeninja

Are there any good configuration file reading libraries for C\C++ that can be used for applications written on the linux platform. I would like to have a simple configuration file for my application. At best i would like to steer clear of XML files that might potentially confuse users.

有没有好的C\C++配置文件读取库,可以用于linux平台上编写的应用程序。我想为我的应用程序提供一个简单的配置文件。充其量我想避开可能会混淆用户的 XML 文件。

采纳答案by Chris Young

回答by ayaz

I would recommend 'libconfig'.

我会推荐' libconfig'。

回答by jk.

Another option is Boost.PropertyTree(doc). It allows to read/write XML, INI, JSON and Info files. And you get portability for free.

另一种选择是Boost.PropertyTree( doc)。它允许读/写 XML、INI、JSON 和信息文件。而且您可以免费获得便携性。

回答by 1800 INFORMATION

Boost program_optionsThis allows you to read program options from config files, environment variables and the command line. It is portable and very easy to use.

Boost program_options这允许您从配置文件、环境变量和命令行读取程序选项。它是便携式的,非常易于使用。

回答by Mark Baker

If you just want a simple config file, with a list of commands and/or variable settings, then it's very easy to write your own parser, so easy that it's probably not worth using a library. If you need something more complicated then the parser rapidly becomes more complicated and an existing library is worth using.

如果您只想要一个简单的配置文件,带有命令和/或变量设置列表,那么编写自己的解析器非常容易,很容易以至于可能不值得使用库。如果您需要更复杂的东西,那么解析器会迅速变得更加复杂,并且值得使用现有的库。

I've never tried using libconfig, but it looks like a good choice, and I like the format of the config files it uses.

我从未尝试过使用 libconfig,但它看起来是一个不错的选择,而且我喜欢它使用的配置文件的格式。

You need to decide whether you want your program to be able to write config files. If it's a GUI program, you probably do. This will affect what libraries are suitable.

您需要决定是否希望您的程序能够编写配置文件。如果它是一个 GUI 程序,你可能会这样做。这将影响哪些库是合适的。

回答by Craig McQueen

For a single app, you could consider libconfuse.

对于单个应用程序,您可以考虑libconfuse

If you need to be able to handle a wide variety of config file formats (e.g. for a web portal for a system, which needs to read and write config files from many apps in many formats), there is Augeas.

如果您需要能够处理多种配置文件格式(例如,对于需要从许多应用程序以多种格式读取和写入配置文件的系统的门户网站),则可以使用Augeas

回答by lothar

The question is what file format did you have in mind? The attribute "simple" is a bit of an underspecification. If you are looking for a library that can use "windows .ini formated" config files you may want to check out ACE http://www.cs.wustl.edu/~schmidt/ACE/.

问题是你想到了什么文件格式?属性“简单”有点欠规范。如果您正在寻找可以使用“windows .ini 格式”配置文件的库,您可能需要查看 ACE http://www.cs.wustl.edu/~schmidt/ACE/