4号的 囧 当时忙着小游戏项目 现在才写。。唉~
- //////////////////////////////////////////////////////////////////////////
- // CopyRight(c) 2009, YOYO, All Rights Reserved.
- // Author: LIN YiQian
- // Created: 2009/09/17
- // Describe: INI文件读取练习
- //////////////////////////////////////////////////////////////////////////
- #include <Windows.h>
- #include <iostream>
- void main(void)
- {
- // 读整数
- UINT nResult = GetPrivateProfileInt("pic", "count", 0, ".//config.ini");
- std::cout << nResult << std::endl;
- // 读文本
- char szStr[256];
- memset(szStr, 0, sizeof(szStr));
- GetPrivateProfileString("string", "Display", "", szStr, sizeof(szStr), ".//config.ini");
- std::cout << szStr << std::endl;
- // 写文本
- WritePrivateProfileString("YOYO", "name", "linyq", ".//config.ini");
- // 写段
- WritePrivateProfileSection("CLASS", "company=tq/0date=20090817/0number=48/0", ".//config.ini");
- // 读取段
- GetPrivateProfileSection("CLASS", szStr, sizeof(szStr), ".//config.ini");
- char* p = szStr;
- while (p != NULL)
- {
- std::cout << p << std::endl;
- p = strtok(p + strlen(p) + 1, "/0");
- }
- system("pause");
- return;
- }