zoukankan      html  css  js  c++  java
  • VC++读写配置文件.ini

    1.首先.ini文件的编码形式必须是Unicode,可通过文件另存为修改;

    2.获取配置文件路径(注:我是放在.exe执行文件的根目录下的)

    CString   sPath;  
    CString StrName;
    StrName="dasdasda";
    GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);   
    sPath.ReleaseBuffer();  //到这一步获取的是执行文件(.exe)的路径 
    int   nPos;   
    nPos=sPath.ReverseFind('\');   
    sPath=sPath.Left(nPos);   
    CString   lpszFile=sPath+"\uilib.ini";//这里是配置文件路径

    3.写入配置文件(若配置文件中已存在cityname,则会覆盖它所对应的值)

    WritePrivateProfileString(CString("AttenCitys"),CString("cityname"),StrName,lpszFile);

    4.读取配置文件

    CString str;
    GetPrivateProfileString(CString("AttenCitys"),CString("cityname"),CString("NULL"),str.GetBuffer(),MAX_PATH,lpszFile);
    str.ReleaseBuffer();
  • 相关阅读:
    叶问14
    叶问13
    叶问12
    叶问11
    叶问10
    叶问9
    Java三种循环之间的区别
    利用Java对象数组制作简易学生管理系统
    什么叫java方法重载?
    Java编译器的常量优化
  • 原文地址:https://www.cnblogs.com/fuge/p/3195578.html
Copyright © 2011-2022 走看看