Ace reads configuration documents in ini format

Source: Internet
Author: User

 

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# ">
  1. # Include <ACE/ace. h>
  2. # Include <ACE/configuration_import_export.h>
  3. # Include <iostream>
  4. Using NamespaceSTD;
  5. IntReadfromini (Const Char* Szini );
  6. IntMain (IntArgc,Char** Argv)
  7. {
  8. Readfromini ("test. ini ");
  9. Return0;
  10. }
  11. IntReadfromini (Const Char* Szini)
  12. {
  13. Ace_configuration_heap config;
  14. Ace_ini_impexp INI (config );
  15. Config. open ();
  16. If(-1 = ini. import_config (szini ))
  17. {
  18. Ace_error_return (lm_error, "error open config file/N"),-1 );
  19. }
  20. Ace_configuration_section_key key_network;
  21. Config. open_section (config. root_section (), "mc_app", 0, key_network );
  22. Ace_tstring value;
  23. Config. get_string_value (key_network, "mc_ip", value );
  24. Cout <"IP =" <value. c_str () <Endl ;;
  25. Config. get_string_value (key_network, "mc_port", value );
  26. IntPort = atoi (value. c_str ());
  27. Cout <"Port =" <port <Endl;
  28. Ace_debug (lm_notice, "will listen on port % d/N", Port ));
  29. Return0;
  30. }
#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.