c++讀取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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM