Understanding the INI file structure and programmatic reading

Source: Internet
Author: User

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

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.