INI format data generation and parsing

Source: Internet
Author: User
Tags readfile

INI Format data generation and parsing

1, INI format data long what kind?
2, INI format data introduction
INI file is derived from the English "initial (Initial) "is the acronym, which corresponds to its purpose--the initialization program. Sometimes, the INI file will also have a different extension, such as ". Cfg ",". conf"(also used in Linux systems), or". txt "instead(not recommended from the perspective of recognition)。

3. ini format data applicable scenarios

INI fileis a configuration file with no fixed standard format. It is composed of simple text and simple structure, often used in Windows or other OS (Linux, etc.).
4, common open-source cinifile notes?Http://www.codeforge.cn/read/181985/memleak_test.cpp__html
1) include IniFile.h and iniFile.cpp in their own projects; 2) The configuration file path initialization is required when reading, function interface: constructor or Initialize (). All configuration file ini is required before parsingThe format data is read into the buffer to parse, function Interface: ReadFile ().
5. Constructing INI Format data
INI file initialization, write file test. void Buildandwriteinitofile () {Cinifile iniFile ("./ini_oracle_test.ini");//Read File Inifile.readfile ();//Read the number of sessions in the INI file. cout << "Nkeys =" << Inifile.numkeys () << endl;//new add array_data new Data Inifil   E.setvalue ("Section3", "task_id", "3"); The format is: Session--key--value form. Inifile.setvalue ("Section3", "system_id", "a") Inifile.setvalue ("Section3", "task_ NAME "," \ "test\" "); Inifile.setvalue (" Section3 "," Start_time "," 2 May-November-14 02.49.00.000000000 pm "); Inifile.setvalue (" Section3 "," End_time "," 2 May-November-14 02.55.00.000000000 PM "), Inifile.setvalue (" Section3 "," event_id "," 3 "); Inifile.setvalue ("Section3", "Auto_probe", "N");//write to File Inifile.writefile ();//Lookup what we had now. Query Key number. for (unsigned KeyID = 0; KeyID < Inifile.numkeys (); ++keyid) {cout << "Key =" << inifile.keyname (  KeyID) << endl;//Query the value number of the key. for (unsigned valueid = 0; ValueID < inifile.numvalues (KeyID); ++valueid) {cout << "ValueName =" << iniFile.valuename (KeyID, ValueID) << "Value =" << inifile.getvalue (KeyID, ValueID) << Endl;} End for Valueid}//end for KeyID}



6. Parsing INI Format data
Read and parse Inifilevoid Readandparseserverini () {const string strconfigpath = string (g_pszserverconfig); Cinifile inifile;//initialization, set INI file path. inifile.initialize (Strconfigpath);//Read file. Inifile.readfile ();/***************** [listen]listen_port=7200*********************************************** Gets the value of the corresponding session for listen, key for listen_port. int nport = Inifile.getvaluei ("Listen", "listen_port"); cout << nport << endl;string strdbip = Inifile.getvalue ("Oracle_conn_info", "Dbip"); int idbport = inifile.g Etvaluei ("Oracle_conn_info", "Dbport"); string strdbsid = Inifile.getvalue ("Oracle_conn_info", "Dbsid"); string Strdbusername = Inifile.getvalue ("Oracle_conn_info", "Dbusername"); string Strdbpassword = Inifile.getvalue ("Oracle_ Conn_info "," Dbpassword "), cout << strdbip <<" \ t "<< idbport <<" \ t "<< strdbsid <<" \ T "<< strdbusername <<" \ t "<< Strdbpassword << endl;//get each key under the corresponding sessionName. String strpath = Inifile.getvaluename ("Envconfig", 0); string strtnsname = Inifile.getvaluename ("Envconfig", 1); string Strnlslang = Inifile.getvaluename ("Envconfig", 2), cout << strpath << "\ t" << strtnsname << "\ T" &l t;< Strnlslang << endl;//Gets the logarithm of "Key-value" under a session. cout << inifile.numvalues ("Envconfig") << Endl;}




7. ini Format Data parsing source: http://download.csdn.net/detail/wojiushiwo987/8871011
8, the operation results indicate:
PostScript:1) Project found in the company of the. ini,. conf format data There are multiple versions of the resolution, most of them are written by their predecessors, most of them are large and small bugs, inconvenient for their own use. And the above cinifile is easy to use,no need to repeat "build wheels", which can be easily ported to the project. 2) Several minor changes have been made to the author's code discovery, and the subsequent discovery of bugs will continue to update the code.

2014-7-5 pm18:59 at home in front of the bed

Ming Yi World

Reprint please indicate source, original address: http://blog.csdn.net/laoyang360/article/details/46764715

If you feel this article is helpful, please click on the ' top ' support, your support is I insist on writing the most power, thank you!



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

INI format data generation and parsing

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.