读写ini文件

来自http://tunps.com/read-write-ini-file

WritePrivateProfileString("student","Name","xiaotun","c:\\setting.ini");

WritePrivateProfileString() 是往ini里面写入内容,"student"是section name,"Name"是key,"xiaotun"是value,c:\\setting.ini是指定写入的文件,必须是绝对路径,否则搜索%systemroot%目录

写入的文件内容是
[student]
Name=xiaotun

WritePrivateProfileString("student","Name","xiaotun","c:\\setting.ini");
WritePrivateProfileString("student","Age","18","c:\\setting.ini");

写入的内容是:
[student]
Name=xiaotun
Age=18

读取:
DWORD GetPrivateProfileString(
LPCTSTR lpAppName, // points to section name
LPCTSTR lpKeyName, // points to key name
LPCTSTR lpDefault, // points to default string
LPTSTR lpReturnedString, // points to destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // points to initialization filename
);

例如:

GetPrivateProfileString(NULL,NULL,NULL,buf,sizeof(buf),"D:\\Debug\\test.inf");

和Write基本一样,只是第三个参数LPCTSTR lpDefault是当lpKeyName没有找到的时候的默认keyname。

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>