c/c++常用代码 -- ini文件操作
#pragma once
#include <string>
#include <sstream>
typedef std::basic_string<TCHAR> tstring;
class CIniCfg
{
public:
CIniCfg()
{
TCHAR szTemp[MAX_PATH];
GetModuleFileName(NULL, szTemp, sizeof(szTemp));
LPTSTR p = _tcsrchr(szTemp, _T('.'));
if (p != NULL)
_tcscpy(p, _T(".ini"));
else
_tcscat(szTemp, _T(".ini"));
m_strFilePath = szTemp;
}
void SetName(LPCTSTR szName)
{
TCHAR szTemp[MAX_PATH];
GetModuleFileName(NULL, szTemp, sizeof(szTemp));
LPTSTR p = _tcsrchr(szTemp, _T('\\'));
if (p != NULL)
{
_tcscpy(++p, szName);
}
m_strFilePath = szTemp;
}
void SetPath(LPCTSTR szPath)
{
m_strFilePath = szPath;
}
BOOL SetInt(LPCTSTR lpAppName, // pointer to section name
LPCTSTR lpKeyName, // pointer to key name
int nValue)
{
std::basic_stringstream<TCHAR> ss;
ss << nValue;
return WritePrivateProfileString(
lpAppName,
lpKeyName,
ss.str().c_str(), //strValue,
m_strFilePath.c_str());
}
BOOL SetString(LPCTSTR lpAppName, // pointer to section name
LPCTSTR lpKeyName, // pointer to key name
LPCTSTR lpString) // pointer to string to add
{
return WritePrivateProfileString(
lpAppName,
lpKeyName,
lpString,
m_strFilePath.c_str());
}
int GetInt(LPCTSTR lpAppName, // address of section name
LPCTSTR lpKeyName, // address of key name
int nDefault) // return value if key name is not found
{
return GetPrivateProfileInt(
lpAppName,
lpKeyName,
nDefault,
m_strFilePath.c_str());
}
tstring GetString(LPCTSTR lpAppName, // points to section name
LPCTSTR lpKeyName, // points to key name
LPCTSTR lpDefault) // points to default string
{
TCHAR szRet[MAX_PATH] = {};
DWORD dwSize = MAX_PATH;
GetPrivateProfileString(
lpAppName, // points to section name
lpKeyName, // points to key name
lpDefault, // points to default string
szRet, // points to destination buffer
dwSize, // size of destination buffer
m_strFilePath.c_str());
return szRet;
}
protected:
tstring m_strFilePath;
};
c/c++常用代码 -- ini文件操作的更多相关文章
- ini文件操作
Config.ini 文件操作 [SYS] sysname=hy company=hyhy tel=2 using System; using System.Collections.Generic; ...
- ini 文件操作记要(1): 使用 TIniFile
ini 文件操作记要(1): 使用 TIniFile unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Class ...
- winform INI文件操作辅助类
using System;using System.Runtime.InteropServices;using System.Text; namespace connectCMCC.Utils{ // ...
- [C#] 常用工具类——文件操作类
/// <para> FilesUpload:工具方法:ASP.NET上传文件的方法</para> /// <para> FileExists:返回文件是否存在&l ...
- Ini文件操作类
/// <summary> /// Ini文件操作类 /// </summary> public class Ini { // 声明INI文件的写操作函数 WritePriva ...
- ansible笔记(5):常用模块之文件操作(二)
ansible笔记():常用模块之文件操作(二) 文件操作类模块 find模块 find模块可以帮助我们在远程主机中查找符合条件的文件,就像find命令一样. 此处我们介绍一些find模块的常用参数, ...
- C# ini文件操作【源码下载】
介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...
- C#读写ini文件操作
ini文件,是windows操作系统下的配置文件,ini文件是一种按照特点方式排列的文本文件,它的构成分为三部分,结构如下: [Section1] key 1 = value2 key 1 = val ...
- C# Ini文件操作
在开源中国看到的操作ini文件的,写的还不看,留着以后用 using System; using System.IO; using System.Runtime.InteropServices; us ...
随机推荐
- h5 吸顶效果 顶部悬浮
window.onscroll = function(){ var scrollTop = document.documentElement.scrollTop || document.body.sc ...
- STM32F05 学习中............
今天,拿到stm32f05的板子已经三个月了吧,但是没有真的研究过,真的对板子过意不去了...所以决定今天好好的对待我的板子.
- Unieap3.5-需要用到window.setTimeout的地方
1.js大数据量操作且需要显示进度条 unieap.showLoading(true);//进度条 window.setTimeout(function(){ checkUtils.setAllRow ...
- Java c3po
1.准备通用类 (引用:c3p0-0.9.1.2.jar) package nankang.test; import java.sql.Connection; import com.mchange.v ...
- read 不回显的方法
方法就是: stty -echo #设置输入字符不回显 #此处用read语句接收用户输入的内容 stty echo #取消不回显状态 stty erase '^H'
- 软件工程 speedsnail 冲刺9
20150313 完成任务:为周五检查做了相关准备,包括稳定性测试,分辨率测试: 遇到问题: 问题1 进入关卡的开始蜗牛会跳一段距离 解决1 没有解决 明日任务: 冲刺结束
- Dev的DocumentManager 相关问题
1.改变DocumentManager包含的窗体的排列方式 if (this.documentManager1.View.Type != ViewType.NativeMdi) { this.docu ...
- ViewGroup 和 View 事件传递及处理小谈
前言 在自定义组件的时候少不了会去处理一些事件相关的东西,关于事件这块网上有很多文章,有说的对的也有说的不对的,我在理解的时候也有过一段时间的迷惑,现在把自己理解的东西写下来,给有相同疑问的朋友提供些 ...
- PHP 下载文件时自动添加bom头的方法
首先弄清楚,什么是bom头?在Windows下用记事本之类的程序将文本文件保存为UTF-8格式时,记事本会在文件头前面加上几个不可见的字符(EF BB BF),就是所谓的BOM(Byte order ...
- LinkedList存储一副扑克牌,实现洗牌功能。
package cd.itcast.runble; import java.util.LinkedList; import java.util.Random; /** * LinkedList存储一副 ...