ACE读取ini格式的配置文档
不多说了,功能很清楚,从ini格式文档读取配置信息进来。
不过在使用中发现好像读进来的数据只能是字符串类型(get_integer_value好像不管用)
- #include <ace/ace.h>
- #include <ace/Configuration_Import_Export.h>
- #include <iostream>
- using namespace std;
- int ReadFromIni(const char* szIni);
- int main(int argc, char** argv)
- {
- ReadFromIni("test.ini");
- return 0;
- }
- int ReadFromIni(const char* szIni)
- {
- ACE_Configuration_Heap config;
- ACE_Ini_ImpExp ini(config);
- config.open();
- if( -1==ini.import_config(szIni) )
- {
- ACE_ERROR_RETURN( (LM_ERROR,"error open config file/n"),-1 );
- }
- ACE_Configuration_Section_Key key_network;
- config.open_section(config.root_section(),"mc_app",0,key_network);
- ACE_TString value;
- config.get_string_value(key_network,"mc_ip",value);
- cout << "ip = " << value.c_str() << endl;;
- config.get_string_value(key_network,"mc_port",value);
- int port=atoi(value.c_str());
- cout << "port = " << port << endl;
- ACE_DEBUG((LM_NOTICE,"will listen on port %d/n",port));
- return 0;
- }
#include <ace/ace.h>
#include <ace/Configuration_Import_Export.h>
#include <iostream>
using namespace std;
int ReadFromIni(const char* szIni);
int main(int argc, char** argv)
{
ReadFromIni("test.ini");
return 0;
}
int ReadFromIni(const char* szIni)
{
ACE_Configuration_Heap config;
ACE_Ini_ImpExp ini(config);
config.open();
if( -1==ini.import_config(szIni) )
{
ACE_ERROR_RETURN( (LM_ERROR,"error open config file/n"),-1 );
}
ACE_Configuration_Section_Key key_network;
config.open_section(config.root_section(),"mc_app",0,key_network);
ACE_TString value;
config.get_string_value(key_network,"mc_ip",value);
cout << "ip = " << value.c_str() << endl;;
config.get_string_value(key_network,"mc_port",value);
int port=atoi(value.c_str());
cout << "port = " << port << endl;
ACE_DEBUG((LM_NOTICE,"will listen on port %d/n",port));
return 0;
}
//ini文件格式
[mc_app]
mc_ip="127.0.0.1"
mc_port=11211