C + + read. ini configuration file __c++

Source: Internet
Author: User

Note the method for reading the. ini configuration file.

In practice, the path to the current program (or a specific profile directory) is usually first obtained.

GetModuleFileName

Explain this sentence: STRRCHR (cfgpath, ' \ \ ') [0] = ' n ';

STRRCHR (cfgpath, ' \ \ ') returns the last occurrence of the ' \ ' in the path, STRRCHR (Cfgpath, ' \ \ ') [0] changes the position to '. After strcat, the absolute address of the configuration file is obtained.

Getprivateprofilestringa (Here is the string, there are other types) is to get the configuration file corresponding to the function, it must be absolute path.

Char Cfgpath[max_path];
int bdenoise = 0;
if (GetModuleFileNameA (NULL, Cfgpath, MAX_PATH) > 0)
{
strrchr (cfgpath, ' \ \ ') [0] = ';
strcat (Cfgpath, "\\config.ini");
			
Char tmp[8];
Getprivateprofilestringa ("Denoise", "Denoise", "0", TMP, 8, cfgpath);
Bdenoise = atoi (TMP);
				
}

There is also a wide-character notation:

TCHAR Inifullpath[max_path];
if (GetModuleFileName (NULL, Inifullpath, MAX_PATH) > 0)
{
(_TCSRCHR (Inifullpath, _t (' \ \ \))] [1] = 0;
Wstring strpath = Inifullpath;
strpath = strpath + _t ("Config.ini");
Bdenoise = Getprivateprofileint (L "denoise", L "Denoise", 0, Strpath.c_str ());

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.