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.