c++读取ini的Section节名

本文介绍了一个使用C++读取INI文件中所有Section名称的示例代码,通过GetPrivateProfileSectionNames函数获取并打印出指定INI文件的所有Section名称。

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "iostream"

using namespace std;

const short int max_Section= 20;
const short int MAX_SECTION = 20;

int main()
{
//确定ini地址
LPCTSTR lpFileName="D:\\documents\\visual studio 2015\\Projects\\ConsoleApplication1\\Release\\mysetting.ini";

char chSectionNames[max_Section] = { 0 };//总的提出来的字符串

char chSection[MAX_SECTION] = { 0 };//存放一个小节名

int i;
int pos = 0;

int ret=GetPrivateProfileSectionNames(chSectionNames, max_Section, lpFileName);//获取ini文件Section个数和数据

int m;
for (i = 0; i < max_Section; i++)//循环得到Section节名
{

if (chSectionNames[i] == 0 && chSectionNames[i + 1] != 0)//判断Section节名是否存在
{
for ( m = pos; m <= i; m++)

{

chSection[m - pos] = chSectionNames[m];//获取小节名
cout << chSection[m - pos] ;
}
pos = i + 1;

CString str;
str.Format("%s", chSection);

cout << str << endl;

}
}


system("pause");
return 0;
}

 

转载于:https://www.cnblogs.com/SZJH/p/10514519.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值