ini文件里写
ID=123
NAMD=ASDFGHVC里怎么读INI文件里的内容,用什么类?

解决方案 »

  1.   

    ini文件应这样写:
    [项目]
    ID=123
    NAMD=ASDFGH  char buff[50];
      memset(buff,0,50);
      GetPrivateProfileString("项目","ID",“默认值”buff,50,"???.ini");
    请见MSDN中关于GetPrivatePorfileString函数的说明!
      

  2.   

    http://crob.net/vc/source/inifile.zip我前两天写的INI类,已经用在我的项目里了,比较简单,但是可以保存并读取CString,double,CTime,dword等类型的设置项目
      

  3.   

    读BOOL CIniFileEx::ReadValue(CString Section, CString Ident, DWORD &Value, DWORD defValue)
    {
    char *pstrReturn=new char[30];
    CString strDef="";
    strDef.Format("%d", defValue);
    if(!GetPrivateProfileString(Section, Ident, strDef, pstrReturn, 30, m_sFileName)){
    Value=0;
    delete []pstrReturn;
    return FALSE;
    }
    Value = atol(pstrReturn); delete []pstrReturn;
    return TRUE;
    }写
    BOOL CIniFileEx::WriteValue(CString Section, CString Ident, DWORD Value)
    {
    if(!fCreated)return FALSE;
    CString strValue;
    strValue.Format("%d", Value);
    return WritePrivateProfileString(Section, Ident, strValue, m_sFileName);}
      

  4.   

    BOOL CIniFileEx::WriteValue(CString Section, CString Ident, CTime Value)
    {
    if(!fCreated)return FALSE;
    CString strValue;
    time_t lDate=Value.GetYear()*10000 + Value.GetMonth()*100 + Value.GetDay();
    strValue.Format("%d", lDate);
    return WritePrivateProfileString(Section, Ident, strValue, m_sFileName);}BOOL CIniFileEx::ReadValue(CString Section, CString Ident, CTime &Value, CTime defValue)
    {
    char *pstrReturn=new char[30];
    CString strDef="";
    time_t lDate=defValue.GetYear()*10000 + defValue.GetMonth()*100 + defValue.GetDay();
    strDef.Format("%d", lDate); if(!GetPrivateProfileString(Section, Ident, strDef, pstrReturn, 30, m_sFileName)){
    Value=defValue;
    delete []pstrReturn;
    return FALSE;
    }
    lDate = atol(pstrReturn);
    //Value = CTime(lDate);
    int y,m,d;
    y=(lDate/10000)%10000;
    m=(lDate/100)%100;
    d=lDate%100;
    CTime tmpT(y,m,d,0,0,0);
    Value = tmpT; delete []pstrReturn;
    return TRUE;
    }
      

  5.   

    我有一个书签管理器,有点想读ini文件的样子,要的话,你就发个mail给我
    [email protected]
      

  6.   

    int  id=123;
    char chId[50];
    CString strId;
    CString strNamd="ASDFGH";
    DWORD dwLen=20;
    char szTemp[255]={0};char strGetNamd[50]={0};
    int iGetId;
    CString strGetId;::GetCurrentDirectory(250,szTemp);
    strcat(szTemp,"\\test.ini");
    itoa(id,chId,10);
    strId=(CString)chId;
    ::WritePrivateProfileString("项目","ID",strId,szTemp);
    ::WritePrivateProfileString("项目","NAMD",strNamd,szTemp);iGetId=::GetPrivateProfileInt("项目","ID",1234,szTemp);
    ::GetPrivateProfileStrin("项目","NAMD","s",strGetNamd,dwLen,szTemp);

    //strGetId.Format("%d",iGetId);
    //AfxMessageBox(strGetId);
    //AfxMessageBox(strGetNamd);
      

  7.   

    有一个现成的CIniEx类,[section1]
    key1=value1
    key2=value2
    [section1]
    key1=value1
    key2=value2只是支持单行的Value值,不过可以改写为支持多行Value值
    想要吗?