8 Star 29 Fork 36

rubikplanet / ChanlunX

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
IniReader.cpp 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
rubikplanet 提交于 2021-10-09 22:16 . 使用std::vector
#include "IniReader.h"
#include <iostream>
#include <windows.h>
// http://blog.csdn.net/sdcxyz/article/details/10946111
// http://www.codeproject.com/Tips/376146/A-Small-Class-to-Read-INI-Files
CIniReader::CIniReader(LPCTSTR szFileName)
{
memset(m_szFileName, 0x00, sizeof(m_szFileName));
memcpy(m_szFileName, szFileName, _tcslen(szFileName) * sizeof(TCHAR));
}
int CIniReader::ReadInteger(LPCTSTR szSection, LPCTSTR szKey, int iDefaultValue)
{
int iResult = GetPrivateProfileInt(szSection, szKey, iDefaultValue, m_szFileName);
return iResult;
}
float CIniReader::ReadFloat(LPCTSTR szSection, LPCTSTR szKey, float fltDefaultValue)
{
TCHAR szResult[255];
TCHAR szDefault[255];
float fltResult;
_sntprintf_s(szDefault, sizeof(szDefault) - 1, TEXT("%f"), fltDefaultValue);
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
fltResult = (float)_tstof(szResult);
return fltResult;
}
bool CIniReader::ReadBoolean(LPCTSTR szSection, LPCTSTR szKey, bool bolDefaultValue)
{
TCHAR szResult[255];
TCHAR szDefault[255];
bool bolResult;
_sntprintf_s(szDefault, sizeof(szDefault) - 1, TEXT("%s"), bolDefaultValue ? TEXT("True") : TEXT("False"));
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
bolResult = (_tcscmp(szResult, TEXT("True")) == 0 || _tcscmp(szResult, TEXT("true")) == 0) ? true : false;
return bolResult;
}
LPTSTR CIniReader::ReadString(LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szDefaultValue)
{
LPTSTR szResult = new TCHAR[255];
memset(szResult, 0x00, sizeof(szResult));
GetPrivateProfileString(szSection, szKey, szDefaultValue, szResult, 255, m_szFileName);
return szResult;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rubikplanet/ChanlunX.git
git@gitee.com:rubikplanet/ChanlunX.git
rubikplanet
ChanlunX
ChanlunX
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891