INI file read/write in the Console environment

Source: Internet
Author: User

I finally finished reading and writing INI files after an afternoon ~~~~~

Generally, the INI file reads and writes are completed in MFC. This time, it should be implemented in the Console environment. I have been searching for it online for a long time. They are all from the east to the west. They are all the same... It is also implemented under MFC. It seems that there are fewer and fewer people writing things, which is chilling. The most unfortunate thing is that the original words are not repeated. Nm is so clever that it is the same as what people create ...... No more nonsense.

Now, I want to share with you the INI reading and writing I have learned.

In the Console environment, if the header file is written to # include "afx. H "; the program will report an error. here you need to set the compiler. I use vs2008, project-Attribute-General-MFC, and use MFC.

Then add the # include "afx. H" header file. The code below will be shared with you:

// Test. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <iostream> # include" afx. H "# include <string> # include <windows. h> using namespace STD; int _ tmain (INT argc, _ tchar * argv []) {// write the writeprivateprofilestring (_ T ("studentinfo "), _ T ("name"), _ T ("leeboy"), _ T ("D: \ student. ini "); // The number is also written into writeprivateprofilestring (_ T (" studentinfo "), _ T (" Age "), _ T (" 22 "), _ T ("D: \ student. ini "); // read the string cstring strstudname; getprivateprofilestring (_ T (" studentinfo "), _ T (" name "), _ T (" default name "), strstudname. getbuffer (max_path), max_path, _ T ("D: \ student. ini "); // read the integer int result = getprivateprofileint (_ T (" studentinfo "), _ T (" Age "), 0, _ T (" D: \ student. ini "); wcout <(lpctstr) strstudname <Endl; // output of cstring In the Console environment // wcout <strstudname. getstring () <Endl; cout <result; // output number system ("pause"); Return 0 ;}

 

You can write data consecutively as long as the group name is different, such as studentinfo.
 

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.