zoukankan      html  css  js  c++  java
  • MFC读取.ini文件的方法

     

    1. TCHAR tchBuffer[MAX_PATH]; 

    2. LPWSTR curPath; 

    3. curPath = tchBuffer; 

    4. GetCurrentDirectory(MAX_PATH,curPath); 

    5. CString fileName("//sys.ini"); 

    6. CString path(curPath); 

    7. path = path + fileName; 

    8. ::GetPrivateProfileString(L"init",L"Server",L"Localhost",this->server.GetBuffer(20),20,path); 

    9. ::GetPrivateProfileString(L"init",L"UID",L"sa",this->UID.GetBuffer(20),20,path); 

    10. ::GetPrivateProfileString(L"init",L"PWS",L"sa",this->PWD.GetBuffer(20),20,path); 

    11. ::GetPrivateProfileString(L"init",L"DefaultDB",L"master",this->DefaultDB.GetBuffer(20),20,path);

     获取文件路径后,使用GetPrivateProfileString函数读取文件内容参数解释:

    0:区域([])中的字符串

    1key

    2:默认值,若没有找到文件或区域或key这使用默认值

    3:存放值的地址

    4:大小

    5ini文件路径

     

     

    WriteProfileString("Test","id","xym"); 

    //win.ini中创建一个Test节,并在该节中创建一个键id,其值为xym

    ::WritePrivateProfileString("Test","id","xym","d:\\vc\\Ex1\\ex1.ini");

    //Ex1目录下的ex1.ini中创建一个Test节,并在该节中创建一个键id,其值为xym

    //Ex1.ini文件与读写该文件的程序在同一个目录下,则上面语句也可写为:

    ::WritePrivateProfileString("Test","id","xym",".\\ex1.ini");

    需要注意的是,C系列的语言中,转义字符'\\'表示反斜线'\'。另外,当使用相对路径时,\\前的.号不能丢掉了。

     

  • 相关阅读:
    微信小程序购物商城系统开发系列-目录结构
    微信小程序购物商城系统开发系列-工具篇
    如何用js获取浏览器URL中查询字符串的参数
    Search for a Range
    Search in Rotated Sorted Array
    permutation递归方法
    Permutations
    next permutation
    4Sum
    3Sum Closest
  • 原文地址:https://www.cnblogs.com/yaowen/p/2870276.html
Copyright © 2011-2022 走看看