我用
WritePrivateProfileString
来写ini文件,结果成功了!!但是当我用
GetPrivateProfileInt 或
GetPrivateProfileString
来读ini文件时,数据却读不出来(永远是默认数据),这是为什么呢?最好有具体的实现了的例子。谢谢!

解决方案 »

  1.   

    是不是参数写错了。在看看MSDN吧,上面有例子。
      

  2.   

    注意默认路径的问题,如果只是使用文件名相对路径的话,可能会出这样的问题,windows只在windows目录查找配置文件,使用程序路径+配置文件名构造一个绝对路径,lpFileName 
    [in] Pointer to a null-terminated string that specifies the name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory. 
      

  3.   

    ...:OnRead()
    {
    int nCount=::GetPrivateProfileInt("StudentCount","Count",0,".\\Student.ini");
    for(int i=0;i<nCount;i++)
    {
    CString StrKeyName,StrStudentName;
    StrKeyName.Format("Name %d",i);
    ::GetPrivateProfileString("studentName",StrKeyName,NULL,StrStudentName.GetBuffer(128),128,".\\Student.ini");}
    }