Spl*_*ter 2 c c++ unix configuration-files
在哪里可以找到用于读取和操作Unix配置文件的C或C++库(format: name=value\n)?
我建议你使用boost :: property_tree库来实现C++.它有安静的详细手册.此外,我建议你使用"info"配置文件.
配置文件示例:
; this is just comment line
firstParamSection
{
stringParam "string"
intParam 10
}
Run Code Online (Sandbox Code Playgroud)
从配置文件中检索此参数的代码示例:
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <string>
int main (int argc, char *argv[]) {
std::string testString;
int testInt;
boost::property_tree::ptree pTree;
try {
read_info("test/config/file/name", pTree);
}
catch (boost::property_tree::info_parser_error e) {
std::cout << "error" << std::endl;
}
try {
testString = pTree.get<std::string>("firstParamSection.stringParam");
testInt = pTree.get<int>("firstParamSection.intParam");
}
catch(boost::property_tree::ptree_bad_path e) {
std::cout << "error" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5199 次 |
| 最近记录: |