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 ...
随机推荐
- VC与JavaScript交互(三) --- CWebPage类调用javascript函数(给js函数传参,并取得返回值)
①需要一个别人写好的类CWebPage,将其对于的两个文件WebPage.h和WebPage.cpp添加到工程中. ②添加WebBrowser控件,在视图/对话框类的头文件中#include &quo ...
- extern “C”原理,用法以及使用场景-2016.01.05
1 问题提出 在编程过程中,经常发现如下用法: #ifndef _FILE_NAME_H_ #define _FILE_NAME_H_ #ifdef __cplusplus extern " ...
- SQL更新表的字段
Oracle: alter table CAPIAGENTLOG modify(clientcode nvarchar2()) SQL Server: alter table CAPIAGENTLOG ...
- 《你是我的小羊驼》游戏ios源码
<ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op>源码下载:http://code. ...
- 通过Migration在EF6中用多个DbContext
通过Migration在EF6中用多个DbContext EF EF6 C# Migration 通过Migration在EF6中用多个DbContext 前言 实现目标 设置多数据上下文 更新数据脚 ...
- Mysql的ssl主从复制+半同步主从复制
Mysql的ssl主从复制+半同步主从复制 准备工作 1.主从服务器时间同步 [root@localhost ~]# crontab -e */30 * * * * /usr/sbin/ntpdate ...
- DPDK多核多线程机制简析
DPDK通过在多核设备上,创建多个线程,每个线程绑定到单独的核上,减少线程调度的开销,以提高性能. DPDK的线程分为控制线程和数据线程,控制线程一般绑定到MASTER核上,主要是接受用户配置,并传递 ...
- js ajax乱码查看\u8fdb\u53e3
document.write('\u8fdb\u53e3') //在页面上看乱码转为中文 或在按F12 在console里查看 直接打'\u8fdb\u53e3'
- 使用MySQL数据库
登录到MySQL 当 MySQL 服务已经运行时, 我们可以通过MySQL自带的客户端工具登录到MySQL数据库中, 首先打开命令提示符, 输入以下格式的命名: mysql -h 主机名 -u 用户名 ...
- ListView的几种形式
一. ArrayAdapter ListView listView = (ListView) findViewById(R.id.list_view);//ListView的参数为id listVie ...