c++写配置文件
c++写配置⽂件1. 类定义
// ini.h: interface for the Cini class.
#if !defined(AFX_INI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_)
#define AFX_INI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_9月9日忆山东兄弟 古诗
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//#include <afxwin.h>
class __declspec(dllexport)Cini
{
public:
static DWORD ReadString (char *section, char * key,  char* stringtoread  ,  char * filename);
static BOOL  WriteString(LPCTSTR section, LPCTSTR key,char* stringtoadd, char *filename);
Cini();
virtual ~Cini();
};
#endif // !defined(AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_)
1. 类实现
国庆寄语
// ini.cpp: implementation of the Cini class.
#include "stdafx.h"
#include "ini.h"
//#include "vld.h"
/
//Cini类的构造函数和析构函数
Cini::Cini()
{
}
Cini::~Cini()
{
}
/
//写字符串到INI⽂件,GetLastError()函数⽤于返回写⼊失败
void error(LPSTR lpszFunction)
{
CHAR szBuf [80] ;
DWORD dw = GetLastError();
sprintf_s(szBuf, 80, "%s failed: GetLastError returned %u\n",lpszFunction, dw);
MessageBox(NULL, szBuf, "Error", MB_OK);
ExitProcess(dw);
}
BOOL Cini::WriteString(LPCTSTR section, LPCTSTR key, char *stringtoadd, char *filename) {工行白金信用卡
CHAR FilePath[255];
memset(FilePath, 0 ,255);
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL)
{
::GetModuleFileName(hModule,FilePath,255);
//GetProccessImageFileName(PROCESS_QUERY_INFORMATION ,FilePath,255);
(strrchr(FilePath,'\\'))[1] = 0;
strcat(FilePath,filename);
持有一颗子弹违法吗
}
return ::WritePrivateProfileString(section,key,stringtoadd,FilePath);
}
/
//从INI⽂件中读取字符串
长圆脸
形容波光明净的词语DWORD Cini::ReadString(char *section, char * key,  char* stringtoread  ,  char * filename) {
CHAR FilePath[255];
memset(FilePath, 0 ,255);
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL)
{
::GetModuleFileName(hModule,FilePath,255);
//GetProccessImageFileName(PROCESS_QUERY_INFORMATION ,FilePath,255);
(strrchr(FilePath,'\\'))[1] = 0;
strcat(FilePath,filename);
}
return ::GetPrivateProfileString(section, key,NULL,stringtoread,255,FilePath);
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。