C++读写INI文件
INI文件是一种文本文件,通常用于存储程序配置信息。在C++中读取和写入INI文件是一项非常常见的任务。接下来,我将介绍如何使用C++代码读取和写入INI文件。
读取INI文件
首先,我们需要一个INI文件。假设我们有一个名为“config.ini”的INI文件,其内容如下:
[Database]
Host=localhost
Port=3306
Username=root
Password=123456
Database=test
下面是如何使用C++代码读取INI文件:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
string host, username, password, database;
int port;
char filename[] = "config.ini";
GetPrivateProfileString("Database", "Host", "", host, 255, filename);
port = GetPrivateProfileInt("Database