Ace reads configuration documents in ini format
The function is very clear, and the configuration information is read from the INI format document.
However, it seems that the data read in can only be of the string type (get_integer_value does not seem to work)
CPP Code {
DP. Sh. toolbar. copytoclipboard (this); Return false;
} "Href =" http://andylin02.javaeye.com/blog/445568# ">
- # Include <ACE/ace. h>
- # Include <ACE/configuration_import_export.h>
- # Include <iostream>
- Using NamespaceSTD;
- IntReadfromini (Const Char* Szini );
- IntMain (IntArgc,Char** Argv)
- {
- Readfromini ("test. ini ");
- Return0;
- }
- IntReadfromini (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 );
- IntPort = atoi (value. c_str ());
- Cout <"Port =" <port <Endl;
- Ace_debug (lm_notice, "will listen on port % d/N", Port ));
- Return0;
- }
#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 File Format
[Mc_app]
Mc_ip = "127.0.0.1"
Mc_port= 11211