Understanding INI Files:
INI file is simply created as follows:
[UserInfo]
Username= "Fengyuzaitu"
Password= "88888888"
Save the suffix named INI file, for the above file authoring, add double quotation marks regardless, must be divided into two lines, one line of writing. But the previous [UserInfo] must be noted, can be any character, but wait a while we use programming access, we need to use. ////////////////////////////////////////////////////////////code such as//////////////////////////////////// ////
#include <iostream.h>
#include <stdio.h>
#include <windows.h>
int main ()
{
Char username_input[20];
Char password_input[20];
Char username[20];
Char password[20];
cout<< "Please input username" <<endl;
cin>>username_input;
cout<< "Please input code" <<endl;
cin>>password_input;
GetPrivateProfileString ("UserInfo", "UserName", "" ", username,20," D:\\userinfo.ini ");
GetPrivateProfileString ("UserInfo", "Password", "" ", password,20," D:\\userinfo.ini ");
cout<<username<<endl;
cout<<password<<endl;
if ((strcmp (username_input,username)!=0) | | (strcmp (Password_input,password)!=0))
{
cout<< "failed to log in" <<endl;
}
Else
{
cout<< "Log in Now" <<endl;
}
return 0;
}
Describe the function in detail:
GetPrivateProfileString means that a string is obtained for the entry specified in the initialization file. It is a function structure in the editing language.
Parameter type and description
Lpapplicationname String where you want to find the section name of the entry. This string is not case-sensitive. If set to vbNullString, the list of all subsections of this INI file is loaded in the lpreturnedstring buffer.
Lpkeyname String to get the item name or entry name. This string is not case-sensitive. If set to vbNullString, the list of all items in the specified section is loaded in the lpreturnedstring buffer
Lpdefault String that specifies the default value that is returned when the entry is not found. can be set to null ("")
Lpreturnedstring string, specifying a string buffer with a length of at least nsize
NSize Long, specifying the maximum number of characters to mount to the lpreturnedstring buffer
lpFileName String that initializes the name of the file. If you do not specify a full pathname, Windows looks for files in the Windows directory
Understanding the INI file structure and programmatic reading