zoukankan      html  css  js  c++  java
  • Poco 配置文件读取

    1,ini格式文件

    [myApplication]
    somePath = C: est dat.dat
    someValue = 123

    #include <iostream>
    using namespace std;
    
    #include "Poco/Util/Application.h"
    #include "Poco/Path.h"
    using namespace Poco::Util;
    
    #include "Poco/AutoPtr.h"
    #include "Poco/Util/IniFileConfiguration.h"
    using Poco::AutoPtr;
    using Poco::Util::IniFileConfiguration;
    
    int main(int argc, char** argv)
    {
    	AutoPtr<IniFileConfiguration> pConf(new IniFileConfiguration("Test.ini"));
    	std::string path = pConf->getString("myApplication.somePath");
    	int svalue = pConf->getInt("myApplication.someValue");
    	svalue = pConf->getInt("myApplication.asomeValue",456);
    	std::cout << path << endl;
    	cout << svalue << endl;
    
    	return 0;
    }
    


    2:porperties 格式文件

    key1 = value1
    key2:123
    key3.longValue = this is a Very
    long value
    path=C:\Test.dat

    #include "Poco/AutoPtr.h"
    using Poco::AutoPtr;
    
    #include "Poco/Util/PropertyFileConfiguration.h"
    using Poco::Util::PropertyFileConfiguration;
    
    int main(int argc, char** argv)
    {
    	AutoPtr<PropertyFileConfiguration> pConf;
    	pConf = new PropertyFileConfiguration("test.properties");
    	std::string key1 = pConf->getString("key1");
    	int value1 = pConf->getInt("key2");
    	std::string logV = pConf->getString("key3.longValue");
    	std::string path = pConf->getString("path");
    	cout << key1 << endl;
    	cout << value1 << endl;
    	cout << logV << endl;
    	cout << path << endl;
    
    	return 0;
    }

    3 : xml 格式文件

    <config>
    <prop1>value1</prop1>
    <prop2>123</prop2>
    <prop3>
    <prop4 attr="value3" />
    <prop4 attr="value4" />
    </prop3>
    </config>

    #include "Poco/AutoPtr.h"
    using Poco::AutoPtr;
    
    #include "Poco/Util/XMLConfiguration.h"
    using Poco::Util::XMLConfiguration;
    
    int main(int argc, char** argv)
    {
    	AutoPtr<XMLConfiguration> pConfig(new XMLConfiguration("test.xml"));
    	std::string prop1 = pConfig->getString("prop1");
    	cout << prop1 << endl;
    
    	int prop2 = pConfig->getInt("prop2");
    	cout << prop2 << endl;
    
    	std::string prop3 = pConfig->getString("prop3");
    	cout << prop3 << endl;
    	
    	std::string prop4 = pConfig->getString("prop3.prop4");
    	cout << prop4 << endl;
    	prop4 = pConfig->getString("prop3.prop4[@attr]");
    	cout << prop4 << endl;
    	prop4 = pConfig->getString("prop3.prop4[1][@attr]");
    	cout << prop4 << endl;
    
    	return 0;
    }


  • 相关阅读:
    PHP琐碎学习
    php输出echo、print、print_r、printf、sprintf、var_dump比较
    跨域
    react中配置路径别名
    react antd less(3.11.1) less-loader(5.0.0) webpack(4.42.0)设置antd的主题
    babel-plugin-import配置babel按需引入antd模块
    react配置less步骤
    react配置less后浏览器报错npm install @babel/core @babel/preset-env node_moduleswebpackhotdev-server.js: Cannot find module '@babel/helper-create-regexp-features-plugin'
    win10配置Java环境变量
    关于自定义组件的组件命名规范
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671669.html
Copyright © 2011-2022 走看看