VC中读写INI文件

在VC2015中读写INI文件,文件以ANSI格式保存,如果以UTF-8保存,可能会产生乱码。

	LPCTSTR  strfile = _T(".//config.ini");
	TCHAR value[255] = { 0 };
	//读键值
	GetPrivateProfileString(
		_T("ui"),
		_T("button1"), 
		_T("default"),
		value,
		200,
		strfile);

	//写键值对
	WritePrivateProfileString(_T("UI"), _T("button1"), _T("启动"), strfile);

	//读整数
	int left = GetPrivateProfileInt(_T("UI"), _T("left"), 0, strfile);
	CString strleft;
	strleft.Format(_T("%d"),left);

	//读出某节的所有键值对
	TCHAR  chSection[1000];
	GetPrivateProfileSection(_T("UI"), chSection, 200, strfile);
	CStringArray list;
	int len;
	TCHAR *pBuf = chSection;
	while ((len = wcslen(pBuf)) > 0)
	{
		list.Add(pBuf);
		pBuf += len + 1;
	}

	//读出某节的所有键名
	TCHAR  chSectionName[1000];
	GetPrivateProfileSectionNames(chSectionName, 200, strfile);
	CStringArray list1;
	int len1;
	TCHAR *pBuf1 = chSectionName;
	while ((len1 = wcslen(pBuf1)) > 0)
	{
		list1.Add(pBuf1);
		pBuf1 += len1 + 1;
	}

原文地址:http://blog.51cto.com/9233403/2070396

时间: 2024-08-14 08:48:35

VC中读写INI文件的相关文章

C#中读写INI文件

INI文件就是扩展名为"ini"的文件.在Windows系统中,INI文件是很多,最重要的就是"System.ini"."System32.ini"和"Win.ini".该文件主要存放用户所做的选择以及系统的各种参数.用户可以通过修改INI文件,来改变应用程序和系统的很多配置.但自从Windows 95的退出,在Windows系统中引入了注册表的概念,INI文件在Windows系统的地位就开始不断下滑,这是因为注册表的独特优点

在VC中读写ini配置文件

配置文件中经常用到ini文件,在VC中其函数分别为: 写入.ini文件:bool WritePrivateProfileString(LPCTSTR lpAppName,LPCTSTR lpKeyName,LPCTSTR lpString,LPCTSTR lpFileName); 读取.ini文件:DWORD GetPrivateProfileString(LPCTSTR lpAppName,LPCTSTR lpKeyName,LPCTSTR lpDefaut,LPSTR lpReturnedS

python3.52 使用configparser模块读写ini文件

使用configparser模块读写ini文件,如果是python 2.7 使用为 import ConfigParser,python 3.2 以后的版本中 ,应当使用import configparser.Python的configparser Module中定义了3个类对INI文件进行操作.分别是RawConfigParser.ConfigParser.SafeConfigParser.模块所解析的ini配置文件是由多个section构成,每个section名用中括号'[]'包含,每个se

在 WinCe 平台读写 ini 文件

在上篇文章开发 windows mobile 上的今日插件时,我发现 wince 平台上不支持例如 GetPrivateProfileString 等相关 API 函数.在网络上我并没有找到令我满意的相应代码,因此我手工自己写了相应的方法.命名规则是,在 PC API 函数的名称前面加上 “Ce” 前缀,这是为了在 PC 平台上调试和使用时,不和系统的 API 函数发生冲突.值得注意的是,在写 CeWritePrivateProfileString 方法时,如果改写后的 ini 文件应该比改写前

C#读写INI文件

C#读写INI文件,需要用到两个API函数 WritePrivateProfileString GetPrivateProfileString 需要特别注意的是:这两个函数中的*.ini文件地址要使用绝对地址 下面程序的功能,是在一个空文件test.ini中,写入一些属性,并读取 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.

C# 读写INI 文件

INI 格式: [Section1] KeyWord1 = Value1 KeyWord2 = Value2 ... [Section2] KeyWord3 = Value3 KeyWord4 = Value4 public class INIClass { public string inipath; [DllImport("kernel32")] private static extern long WritePrivateProfileString( string section

在.net中读写config文件的各种方法(自定义config节点)

http://www.cnblogs.com/fish-li/archive/2011/12/18/2292037.html 阅读目录 开始 config文件 - 自定义配置节点 config文件 - Property config文件 - Element config文件 - CDATA config文件 - Collection config文件 - 读与写 读写 .net framework中已经定义的节点 xml配置文件 xml配置文件 - CDATA xml文件读写注意事项 配置参数的

【python-ini】python读写ini文件

本文实例讲述了Python读写ini文件的方法.分享给大家供大家参考.具体如下: 比如有一个文件update.ini,里面有这些内容: 1 2 3 4 5 6 7 8 [ZIP] EngineVersion=0 DATVersion=5127 FileName=dat-5127.zip FilePath=/pub/antivirus/datfiles/4.x/ FileSize=13481555 Checksum=6037,021E MD5=aaeb519d3f276b810d46642d782

wince中对ini文件的操作

下面是代码 class ZT_INI { /************************************************************************/ /*写操作 * strSection 节 * strKey 键 * strValue 需要写入的值 * strFilePath 配置文件的全路径(wince中只能使用绝对全路径) */ /************************************************************