怎么获得ini文件或文本文件 小节名 之间的内容
如何获得ini文件或文本文件 小节名 之间的内容
获得ini文件小节名->键内容这个会的,如下
[test]
username = 111
以上没什么问题,现在想知道这样的问题,我想获得以下[test1][test2]下面的内容,如何获得,最好有现成的类最好了。
[test1]
test1内容
test1内容
test1内容
test1内容
[test2]
test2内容
test2内容
test2内容
test2内容
test2内容
------解决方案--------------------
一行一行的读取;
CFile 或者 CStdioFile 抽取[test1][test2]下面的内容
------解决方案--------------------
CString sPath=_T("");
::GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath=sPath.Left(sPath.ReverseFind('\\'));
sPath += _T("\\version.ini");
TCHAR chSectionNames[2048]={0};
TCHAR *pSectionName=NULL;
int i,j=0;
::GetPrivateProfileSectionNames(chSectionNames,2048,sPath);
for(i=0;i<2048;i++,j++)
{
if(chSectionNames[0]=='\0')
break;
if(chSectionNames[i]=='\0')
{
pSectionName=&(chSectionNames[i-j]);
j=-1;
////////////////////////////////////////////////////////////
/// you want to do!!!!!
////////////////////////////////////////////////////////////
if(chSectionNames[i+1]==0)
{
break;
}
}
}
红色是你需要添加的代码
获得ini文件小节名->键内容这个会的,如下
[test]
username = 111
以上没什么问题,现在想知道这样的问题,我想获得以下[test1][test2]下面的内容,如何获得,最好有现成的类最好了。
[test1]
test1内容
test1内容
test1内容
test1内容
[test2]
test2内容
test2内容
test2内容
test2内容
test2内容
------解决方案--------------------
一行一行的读取;
CFile 或者 CStdioFile 抽取[test1][test2]下面的内容
------解决方案--------------------
CString sPath=_T("");
::GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath=sPath.Left(sPath.ReverseFind('\\'));
sPath += _T("\\version.ini");
TCHAR chSectionNames[2048]={0};
TCHAR *pSectionName=NULL;
int i,j=0;
::GetPrivateProfileSectionNames(chSectionNames,2048,sPath);
for(i=0;i<2048;i++,j++)
{
if(chSectionNames[0]=='\0')
break;
if(chSectionNames[i]=='\0')
{
pSectionName=&(chSectionNames[i-j]);
j=-1;
////////////////////////////////////////////////////////////
/// you want to do!!!!!
////////////////////////////////////////////////////////////
if(chSectionNames[i+1]==0)
{
break;
}
}
}
红色是你需要添加的代码