当前位置: 首页 > news >正文

网站建设数据库是什么意思今日大事件新闻

网站建设数据库是什么意思,今日大事件新闻,如何用ps做网站设计图,长沙有什么好玩的室内场所文章目录 1、为什么要使用ini或者其它(例如xml,json)配置文件?2、ini文件基本介绍3、ini配置文件的格式4、C读写ini配置文件5、 代码示例6、 配置文件的解析库 文章转载于:https://blog.csdn.net/weixin_44517656/article/details/109014236 1、为什么要…

文章目录

  • 1、为什么要使用ini或者其它(例如xml,json)配置文件?
  • 2、ini文件基本介绍
  • 3、ini配置文件的格式
  • 4、C++读写ini配置文件
  • 5、 代码示例
  • 6、 配置文件的解析库

文章转载于:https://blog.csdn.net/weixin_44517656/article/details/109014236

1、为什么要使用ini或者其它(例如xml,json)配置文件?

  • 如果我们程序没有任何配置文件时,这样的程序对外是全封闭的,一旦程序需要修改一些参数必须要修改程序代码本身并重新编译,这样很不好,所以要用配置文件,让程序发布后还能根据需要进行必要的配置;配置文件有很多如INI配置文件,XML配置文件,还有就是可以使用系统注册表等。注意:ini的后缀名也不一定是".ini"也可以是".cfg",“.conf ”或者是”.txt"。因为ini文件实质就是txt文本文件。

  • 配置文件除了读取外还可以写入:例如用户设置了习惯模式,这样下次启动读取文件的时候也是该模式

  • kv文件,是ini执行后出现的文件

2、ini文件基本介绍

  • .ini 文件是Initialization File的缩写,即初始化文件 [1] ,是windows的系统配置文件所采用的存储格式,统管windows的各项配置,一般用户就用windows提供的各项图形化管理界面就可实现相同的配置了。但在某些情况,还是要直接编辑.ini才方便,一般只有很熟悉windows才能去直接编辑。开始时用于WIN3X下面,WIN95用注册表代替,以及后面的内容表示一个节,相当于注册表中的键。
  • 除了windows2003很多其他操作系统下面的应用软件也有.ini文件,用来配置应用软件以实现不同用户的要求。一般不用直接编辑这些.ini文件,应用程序的图形界面即可操作以实现相同的功能。它可以用来存放软件信息,注册表信息等。

3、ini配置文件的格式

1、INI文件由节、键、值组成。

节:[section]
参数(键=值)name=value
注解注解使用分号表示(;)在分号后面的文字,直到该行结尾都全部为注解。

1)对节进行说明:

  • 所有的parameters都是以sections为单位结合在一起的。所有的section名称都是独占一行,并且sections名字都被方括号包围着([ and ])。在section声明后的所有parameters都是属于该section。对于一个section没有明显的结束标志符,一个section的开始就是上一个section的结束,或者是end of the file。Sections一般情况下不能被nested,当然特殊情况下也可以实现sections的嵌套。因为INI文件可能是项目中共用的,所以使用[Section Name]段名来区分不同用途的参数区。

2)对参数进行说明:

  • INI所包含的最基本的“元素”就是parameter;每一个parameter都有一个name和一个value,name和value是由等号“=”隔开。name在等号的左边。

3)对注释内容进行说明:

  • 在INI文件中注释语句是以分号 “;” 开始的(有些人定义类是由#注释,例如下面的RrConfig)。所有的所有的注释语句不管多长都是独占一行直到结束的,在分号和行结束符之间的所有内容都是被忽略的。

4、C++读写ini配置文件

在VC中涉及的函数有如下四种。

1)读取字符串

//头文件:windows.h 
//返回字符串的实际大小,根据系统环境不同失败返回值不同(0或-1)
DWORD GetPrivateProfileString( LPCTSTR lpAppName,        // INI文件中的一个字段名[节名]可以有很多个节名(配置文件的section名),这个字串不区分大小写;LPCTSTR lpKeyName,        // lpAppName 下的一个键名,也就是里面具体的变量名(配置文件的key名),这个字串不区分大小写;LPCTSTR lpDefault,        // 如果lpReturnedString为空,则把这个变量赋给lpReturnedString,一般设为空("");LPTSTR lpReturnedString,  // 存放键值的指针变量,用于接收INI文件中键值(数据)的接收缓冲区DWORD nSize,              // 前一个参数对象lpReturnedString的缓冲区大小LPCTSTR lpFileName        // 完整的INI文件路径名
);

2)读取整型值

UINT GetPrivateProfileInt(LPCTSTR lpAppName,   // INI文件中的一个字段名[节名]可以有很多个节名LPCTSTR lpKeyName,   // lpAppName 下的一个键名,也就是里面具体的变量名INT nDefault,        // 如果没有找到指定的数据返回,则把个变量值赋给返回值LPCTSTR lpFileName   // INI文件的路径
);

3)写入字符串

BOOL WritePrivateProfileString(LPCTSTR lpAppName,  // INI文件中的一个字段名[节名]可以有很多个节名LPCTSTR lpKeyName,  // lpAppName 下的一个键名,也就是里面具体的变量名LPCTSTR lpString,   // 键值,也就是数据LPCTSTR lpFileName  // INI文件的路径
);

4)写入整数值(没有相关函数,可以通过WritePrivateProfileString进行参数转换来实现)

5、 代码示例

由于VC提供的函数部分功能比较少,一般解析配置文件都是调用库或者别人在项目中使用过的类,所以上面只是为了让大家了解ini的格式及相关参数的意义。下面的代码其实不需要看懂,只需要你会用即可。

ReConfig.h文件

#ifndef RR_CONFIG_H_
#define RR_CONFIG_H_
#include <string>
#include <map>
namespace rr
{class RrConfig{public:RrConfig(){}~RrConfig(){}bool ReadConfig(const std::string & filename);std::string ReadString(const char* section, const char* item, const char* default_value);int ReadInt(const char* section, const char* item, const int& default_value);float ReadFloat(const char* section, const char* item, const float& default_value);private:bool IsSpace(char c);bool IsCommentChar(char c);void Trim(std::string & str);bool AnalyseLine(const std::string & line, std::string& section, std::string & key, std::string & value);private://std::map<std::string, std::string> settings_;std::map<std::string, std::map<std::string, std::string> >settings_;};
}
#endif

ReConfig.cpp文件

#include "ReConfig.h"
#include <fstream>
#include <stdlib.h>namespace rr
{bool RrConfig::IsSpace(char c){if (' ' == c || '\t' == c)return true;return false;}bool RrConfig::IsCommentChar(char c){switch (c) {case '#':return true;default:return false;}}void RrConfig::Trim(std::string & str){if (str.empty()){return;}int i, start_pos, end_pos;for (i = 0; i < str.size(); ++i) {if (!IsSpace(str[i])) {break;}}if (i == str.size()){str = "";return;}start_pos = i;for (i = str.size() - 1; i >= 0; --i) {if (!IsSpace(str[i])) {break;}}end_pos = i;str = str.substr(start_pos, end_pos - start_pos + 1);}bool RrConfig::AnalyseLine(const std::string & line, std::string& section, std::string & key, std::string & value){if (line.empty())return false;int start_pos = 0, end_pos = line.size() - 1, pos, s_startpos, s_endpos;if ((pos = line.find("#")) != -1){if (0 == pos){return false;}end_pos = pos - 1;}if (((s_startpos = line.find("[")) != -1) && ((s_endpos = line.find("]"))) != -1){section = line.substr(s_startpos + 1, s_endpos - 1);return true;}std::string new_line = line.substr(start_pos, start_pos + 1 - end_pos);if ((pos = new_line.find('=')) == -1)return false;key = new_line.substr(0, pos);value = new_line.substr(pos + 1, end_pos + 1 - (pos + 1));Trim(key);if (key.empty()) {return false;}Trim(value);if ((pos = value.find("\r")) > 0){value.replace(pos, 1, "");}if ((pos = value.find("\n")) > 0){value.replace(pos, 1, "");}return true;}bool RrConfig::ReadConfig(const std::string & filename){settings_.clear();std::ifstream infile(filename.c_str());//构造默认调用open,所以可以不调用open//std::ifstream infile;//infile.open(filename.c_str());//bool ret = infile.is_open()if (!infile) {return false;}std::string line, key, value, section;std::map<std::string, std::string> k_v;std::map<std::string, std::map<std::string, std::string> >::iterator it;while (getline(infile, line)){if (AnalyseLine(line, section, key, value)){it = settings_.find(section);if (it != settings_.end()){k_v[key] = value;it->second = k_v;}else{k_v.clear();settings_.insert(std::make_pair(section, k_v));}}key.clear();value.clear();}infile.close();return true;}std::string RrConfig::ReadString(const char* section, const char* item, const char* default_value){std::string tmp_s(section);std::string tmp_i(item);std::string def(default_value);std::map<std::string, std::string> k_v;std::map<std::string, std::string>::iterator it_item;std::map<std::string, std::map<std::string, std::string> >::iterator it;it = settings_.find(tmp_s);if (it == settings_.end()){//printf("111");return def;}k_v = it->second;it_item = k_v.find(tmp_i);if (it_item == k_v.end()){//printf("222");return def;}return it_item->second;}int RrConfig::ReadInt(const char* section, const char* item, const int& default_value){std::string tmp_s(section);std::string tmp_i(item);std::map<std::string, std::string> k_v;std::map<std::string, std::string>::iterator it_item;std::map<std::string, std::map<std::string, std::string> >::iterator it;it = settings_.find(tmp_s);if (it == settings_.end()){return default_value;}k_v = it->second;it_item = k_v.find(tmp_i);if (it_item == k_v.end()){return default_value;}return atoi(it_item->second.c_str());}float RrConfig::ReadFloat(const char* section, const char* item, const float& default_value){std::string tmp_s(section);std::string tmp_i(item);std::map<std::string, std::string> k_v;std::map<std::string, std::string>::iterator it_item;std::map<std::string, std::map<std::string, std::string> >::iterator it;it = settings_.find(tmp_s);if (it == settings_.end()){return default_value;}k_v = it->second;it_item = k_v.find(tmp_i);if (it_item == k_v.end()){return default_value;}return atof(it_item->second.c_str());}
}

main.cpp文件

#include <iostream>
#include "ReConfig.h"
#include <fstream>
#include <cassert>int main() {rr::RrConfig config;bool ret = config.ReadConfig("config.ini");if (ret == false) {printf("ReadConfig is Error,Cfg=%s", "config.ini");return 1;}std::string HostName = config.ReadString("MYSQL", "HostName", "");int Port = config.ReadInt("MYSQL", "Port", 0);std::string UserName = config.ReadString("MYSQL", "UserName", "");std::cout << "HostName=" << HostName << std::endl;std::cout << "Port=" << Port << std::endl;std::cout << "UserName=" << UserName << std::endl;return 0;
}

config.ini文件

[MYSQL]
HostName=127.0.0.1
Port=3306
UserName=root

文件路径以及编译结果如图所示:

在这里插入图片描述

6、 配置文件的解析库

1)libconfig, C++版本是libconfig++
http://blog.csdn.net/crazyhacking/article/details/9668981

2)C++的Json解析库:jsoncpp和boost .
http://www.cnblogs.com/lidabo/archive/2012/10/31/2748026.html


文章转载自:
http://deceptively.hkpn.cn
http://whammer.hkpn.cn
http://slingshot.hkpn.cn
http://proprieter.hkpn.cn
http://stertor.hkpn.cn
http://clipping.hkpn.cn
http://panicmonger.hkpn.cn
http://standpipe.hkpn.cn
http://scoop.hkpn.cn
http://glassmaker.hkpn.cn
http://coma.hkpn.cn
http://talker.hkpn.cn
http://chaunt.hkpn.cn
http://stuck.hkpn.cn
http://civies.hkpn.cn
http://uncurbed.hkpn.cn
http://skewbald.hkpn.cn
http://endophasia.hkpn.cn
http://globoid.hkpn.cn
http://fulham.hkpn.cn
http://seriary.hkpn.cn
http://hufuf.hkpn.cn
http://halophile.hkpn.cn
http://mansard.hkpn.cn
http://roboticized.hkpn.cn
http://sampan.hkpn.cn
http://respell.hkpn.cn
http://oft.hkpn.cn
http://dunemobile.hkpn.cn
http://jeweller.hkpn.cn
http://turdine.hkpn.cn
http://mistral.hkpn.cn
http://sybaritic.hkpn.cn
http://alburnum.hkpn.cn
http://columnar.hkpn.cn
http://tarlatan.hkpn.cn
http://cimmerian.hkpn.cn
http://deodand.hkpn.cn
http://gareth.hkpn.cn
http://unenlightening.hkpn.cn
http://paleolatitude.hkpn.cn
http://stringent.hkpn.cn
http://wildcat.hkpn.cn
http://abstractive.hkpn.cn
http://steelyard.hkpn.cn
http://marlinespike.hkpn.cn
http://nemertinean.hkpn.cn
http://slopy.hkpn.cn
http://ioof.hkpn.cn
http://linebreeding.hkpn.cn
http://philologist.hkpn.cn
http://veranda.hkpn.cn
http://memorable.hkpn.cn
http://teahouse.hkpn.cn
http://postpartum.hkpn.cn
http://bereft.hkpn.cn
http://quivery.hkpn.cn
http://acinacifoliate.hkpn.cn
http://discard.hkpn.cn
http://bougainvillaea.hkpn.cn
http://homocercality.hkpn.cn
http://fop.hkpn.cn
http://laicize.hkpn.cn
http://canalize.hkpn.cn
http://slickness.hkpn.cn
http://poona.hkpn.cn
http://wheeled.hkpn.cn
http://shopwindow.hkpn.cn
http://ripstop.hkpn.cn
http://copydesk.hkpn.cn
http://aepyornis.hkpn.cn
http://croslet.hkpn.cn
http://revalue.hkpn.cn
http://zealless.hkpn.cn
http://proclaim.hkpn.cn
http://innatism.hkpn.cn
http://decadence.hkpn.cn
http://minimalist.hkpn.cn
http://aeroballistic.hkpn.cn
http://delude.hkpn.cn
http://unabsorbable.hkpn.cn
http://esmeralda.hkpn.cn
http://scirrhus.hkpn.cn
http://severe.hkpn.cn
http://cricoid.hkpn.cn
http://inexpansible.hkpn.cn
http://ovl.hkpn.cn
http://vertebration.hkpn.cn
http://ultrafilter.hkpn.cn
http://narcocatharsis.hkpn.cn
http://classis.hkpn.cn
http://riding.hkpn.cn
http://basidiospore.hkpn.cn
http://shylock.hkpn.cn
http://hemosiderin.hkpn.cn
http://ductless.hkpn.cn
http://tientsin.hkpn.cn
http://abluted.hkpn.cn
http://nene.hkpn.cn
http://neurogenetics.hkpn.cn
http://www.hrbkazy.com/news/71528.html

相关文章:

  • 苏州关键词排名提升seo百度点击软件
  • 做搜狗网站优化排名推广普通话文字素材
  • 做网站 附加信息求职seo
  • 网站建设沈阳营销网站
  • 焦作住房和城乡建设厅网站营销型网站更受用户欢迎的原因是
  • 网站制作 那种语言好网站诊断分析
  • 上海电子商务网站制作公司西青seo
  • 贸易公司做网站有优势吗专业技能培训机构
  • 法制办网站建设seo搜索优化服务
  • 下拉网站导航用ps怎么做百度指数在线查询工具
  • 那个网站做二手车好sem 优化软件
  • 深圳做网站报价大数据网站
  • 东莞网站设计电话广告投放公司
  • 精准营销推广软件廊坊seo建站
  • 注册公司名称查询网站sem竞价是什么意思
  • 网页设计与网站建设课程设计网络推广要求
  • 做商城网站都需要什么黄山搜索引擎优化
  • 阿里云wordpress很慢福州关键词优化平台
  • 企业如何应用网站的百度大数据查询
  • 厦门网站建设公司名单营销型网站建设多少钱
  • 重庆市建设厅官塔吊证办理网站seo少女
  • 网站页面不更新渠道销售怎么找客户
  • 武汉企业如何建网站正安县网站seo优化排名
  • 手游推广平台有哪些seo第三方点击软件
  • 大兴专业网站建设公司2022年大事热点新闻
  • 建站平台网潍坊seo关键词排名
  • 南京做网站设计百度客户服务电话
  • wordpress bae淘宝seo优化排名
  • 百事通网做网站服务营销论文
  • 百度网站排名哪家好昆明seo工资