博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vc读写配置文件 .INI
阅读量:4589 次
发布时间:2019-06-09

本文共 1102 字,大约阅读时间需要 3 分钟。

程序所在的文件夹如"c:\\set.ini”

[PARAMS]

time1=8:00

mac1=50e549ab4492   //ini文件的格式如上

 

 

 

CString Readfile(CString strSetion,CString strSubject,CString strFilename) //参数对应上面的例子:

                                                                                                            [PARAMS]、time1、set.ini  三个参数

        TCHAR buf[MAX_PATH];
 TCHAR path[MAX_PATH];
 CString strpath;
        CString strname;
  
        int ren=GetModuleFileName(NULL,path,MAX_PATH);
        strpath=path;
 ren=strpath.ReverseFind(_T('\\'));
        strpath.Delete(ren,strpath.GetLength()-ren);
 strpath=strpath+"\\"+strFilename;
        ren=GetPrivateProfileString(strSetion,strSubject,0,buf,MAX_PATH,strpath);
        if(!ren) renturn NULL;
        strname.Format("%s",buf);
        return strname;
}

int Writefile(CString strSetion,CString strSubject,CString &strfile,CString strFilename)//

{
        TCHAR buf[MAX_PATH];
 TCHAR path[MAX_PATH];
 CString strpath;
        CString strname;
  
        int ren=GetModuleFileName(NULL,path,MAX_PATH);
        strpath=path;
 ren=strpath.ReverseFind(_T('\\'));
        strpath.Delete(ren,strpath.GetLength()-ren);
 strpath=strpath+"//"+strFilename;
        ren=WritePrivateProfileString(strSetion,strSubject,strfile,strpath);
        if(!ren) return 0;
        return 1;  

}

转载于:https://www.cnblogs.com/xiaoluyiqing/archive/2012/02/27/2370144.html

你可能感兴趣的文章
c# 属性说明
查看>>
c# 方法成员
查看>>
c# 定义和调用索引器
查看>>
c# 引用参数-ref
查看>>
c# 多态
查看>>
c# 参数数组
查看>>
c# 虚属性
查看>>
c# 子类的声明
查看>>
c# 类嵌套
查看>>
c# 方法的隐藏
查看>>
c# 接口实现
查看>>
c# 密封类
查看>>
c# is运算符
查看>>
c# 抽象类与接口
查看>>
c# 委托
查看>>
c# 接口使用
查看>>
c# 事件
查看>>
c# as运算符
查看>>
c# 调试过程
查看>>
c# 结构
查看>>