What Is a Here Document?
In the field of computer science, a configuration file (English: a configuration file in Taiwan) is a computer file that can configure parameters and initial settings for some computer programs.
- Various
- A configuration file is composed of two parts:
- 1. Comment content: In the example file, a single line comment is indicated by # to explain some necessary content.
- 2. Configuration item content: The configuration content is actually a record of key-value pairs, with the key value on the left, such as the name value here, and the value value on the right, corresponding to wangying here. In the middle of the key-value pair, a symbol = (of course can be customized) is used to split the key value and the value value.
#include <iostream> #include <cstdlib> #include <string> #include <fstream> #include "Config.h" int main () {// Open a write file stream to the config.ini file std :: string strConfigFileName ( "config.ini"); std :: ofstream out (strConfigFileName); // Initialize write comments out << "# test for config read and write \ n"; // Write a pair of configuration records: name = wangying out << "name = wangying \ n"; out.close (); // initialize the Config class Config config (strConfigFileName); // read the key std :: string strKey = "name"; std :: string strValue; strValue = config.Read <std :: string> (strKey); std :: cout << "Read Key" << strKey << "'s Value is" << strValue << std :: endl; // write new Key-value pair std :: string strNewKey = "age"; std :: string strNewValue = "23"; config.Add <std :: string> (strNewKey, strNewValue); // Write the modification of the Config class to the file out. open (strConfigFileName, std :: ios :: app); if (out.is_open ()) {// use C << overloaded operator onfig class out << config; std :: cout << "Write config content success!" << std :: endl;} out.close (); system ("pause"); return 0 ;}
- The results are as follows: