eVC实现INI格式文件操作(Unicode)
2008-12-04 00:18
295 查看
INI文件作为配置文件的一种相信大家都不陌生,但在eVC中并没有我们所熟悉的GetPrivateProfileString,WritePrivateProfileString等可以方便用来操作INI文件的API函数,因此就需要我们自己去实现;
函数定义:
static BOOL WriteProfileString(const CString strSection, const CString strEntry,
const CString strValue, const CString strIniPath);
static CString GetProfileString(const CString strSection, const CString strEntry,
const CString strDefault, const CString strIniPath);
static BOOL WriteProfileInt(const CString strSection, const CString strEntry,
const int iValue, const CString strIniPath);
static int GetProfileInt(const CString strSection, const CString strEntry,
const int iDefault, const CString strIniPath);
具体实现代码和实例下载:http://download.csdn.net/source/834404(不能下载的可以留下Email)
功能:实现Unicode型的INI格式文件的创建、添加、修改和读取
缺陷:(待改进)
1、在读取某个项下的某个KEY时,若未找到仍会继续找后面项中的相同的KEY值
2、在键名、等于号、键值三者之间不能留空格
注意:INI格式的文件必须是Unicode格式,不支持ANSI格式文件需先转换成Unicode编码
应用实例(BY Favory.Peng)
写INI格式文件
CProfile::WriteProfileString(_T("info"),_T("version"),_T("V1.00"),_T("//My Documents//test.ini"));
CProfile::WriteProfileString(_T("config"),_T("name"),_T("INI读写程序"),_T("//My Documents//test.ini"));
CProfile::WriteProfileInt(_T("config"),_T("value"),200812,_T("//My Documents//test.ini"));
读INI格式文件
CString textval=CProfile::GetProfileString(_T("info"),_T("version"),_T("error"),_T("//My Documents//test.ini"));
AfxMessageBox(textval);
textval=CProfile::GetProfileString(_T("config"),_T("name"),_T("error"),_T("//My Documents//test.ini"));
AfxMessageBox(textval);
INT val=CProfile::GetProfileInt(_T("config"),_T("value"),0,_T("//My Documents//test.ini"));
textval.Format(_T("get value=%d"),val);
AfxMessageBox(textval);
注:CProfile的原始代码来自网络,它是借助CSting类来实现,方法简单明了,但功能还存在一些缺陷,有待进一步改进,需要在使用过程中加以注意。最后感谢原始作者提供代码与大家分享,希望大家共同优化完善它。
函数定义:
static BOOL WriteProfileString(const CString strSection, const CString strEntry,
const CString strValue, const CString strIniPath);
static CString GetProfileString(const CString strSection, const CString strEntry,
const CString strDefault, const CString strIniPath);
static BOOL WriteProfileInt(const CString strSection, const CString strEntry,
const int iValue, const CString strIniPath);
static int GetProfileInt(const CString strSection, const CString strEntry,
const int iDefault, const CString strIniPath);
具体实现代码和实例下载:http://download.csdn.net/source/834404(不能下载的可以留下Email)
功能:实现Unicode型的INI格式文件的创建、添加、修改和读取
缺陷:(待改进)
1、在读取某个项下的某个KEY时,若未找到仍会继续找后面项中的相同的KEY值
2、在键名、等于号、键值三者之间不能留空格
注意:INI格式的文件必须是Unicode格式,不支持ANSI格式文件需先转换成Unicode编码
应用实例(BY Favory.Peng)
写INI格式文件
CProfile::WriteProfileString(_T("info"),_T("version"),_T("V1.00"),_T("//My Documents//test.ini"));
CProfile::WriteProfileString(_T("config"),_T("name"),_T("INI读写程序"),_T("//My Documents//test.ini"));
CProfile::WriteProfileInt(_T("config"),_T("value"),200812,_T("//My Documents//test.ini"));
读INI格式文件
CString textval=CProfile::GetProfileString(_T("info"),_T("version"),_T("error"),_T("//My Documents//test.ini"));
AfxMessageBox(textval);
textval=CProfile::GetProfileString(_T("config"),_T("name"),_T("error"),_T("//My Documents//test.ini"));
AfxMessageBox(textval);
INT val=CProfile::GetProfileInt(_T("config"),_T("value"),0,_T("//My Documents//test.ini"));
textval.Format(_T("get value=%d"),val);
AfxMessageBox(textval);
注:CProfile的原始代码来自网络,它是借助CSting类来实现,方法简单明了,但功能还存在一些缺陷,有待进一步改进,需要在使用过程中加以注意。最后感谢原始作者提供代码与大家分享,希望大家共同优化完善它。
相关文章推荐
- bash 脚本实现的配置文件(ini/inc.sh)的读写操作
- vc++实现avi文件的操作 分类: 文件格式 2014-10-11 16:11 631人阅读 评论(2) 收藏
- Java实现CSV格式文件的读写(操作API)
- Python实现ini文件操作
- VC++操作INI配置文件的实现
- ini配置文件的格式及读取操作
- 创建Unicode格式的INI文件
- c语言实现读取ini文件操作
- C#实现.ini文件读写操作
- Python实现ini文件操作
- 一个java操作ini格式文件的工具类,支持增删查改,不过由于项目所需,只做了针对单行的操作。写得不好求指教。
- INI文件格式以及Java编码实现读取
- python3操作INI格式文件
- C#实现ini文件读写操作
- INI格式文件操作
- 配置文件操作(ini、cfg、xml、config等格式)
- INI文件格式及其操作代码
- java 实现txt文件读取,写入操作实例代码。
- 创建FilenameFilter接口匿名内部类,实现过滤并删除指定格式文件
- XSSF POI工程对Excel 2007 OOXML (.xlsx)文件操作的纯Java实现