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

哪个公司做网站好 知乎网站积分方案

哪个公司做网站好 知乎,网站积分方案,住建部注册中心官网,汽车网站建设模板【C】手搓读写ini文件源码 思路需求#xff1a;ini.hini.cppconfig.confmian.cpp 思路 ini文件是一种系统配置文件#xff0c;它有特定的格式组成。通常做法#xff0c;我们读取ini文件并按照ini格式进行解析即可。在c语言中#xff0c;提供了模板类的功能#xff0c;所以… 【C】手搓读写ini文件源码 思路需求ini.hini.cppconfig.confmian.cpp 思路 ini文件是一种系统配置文件它有特定的格式组成。通常做法我们读取ini文件并按照ini格式进行解析即可。在c语言中提供了模板类的功能所以我们可以提供一个更通用的模板类来解析ini文件。c中和键值对最贴切的就是STL中的map了。所以我使用map作为properties的实际内存存储同时为了方便使用另外多一个set类型的字段记录所有的key。大致流程为 1、逐行扫描文件内容 2、过滤注释#后面的为注释 3、根据等号切割key和value 4、保存section,key和value到文件中 需求 1、当key没有值时可以设定个默认值 2、读取文件时只有KEY没哟默认值会报错添加一个默认值给该KEY 3、修改KEY的值时并保存到文件中形成固定格式 ini.h /********************************************************************************* file : ini.h* author : CircleDBA* mail : weiyuanquankingbase.com.cn* blog : circle-dba.blog.csdn.net* date : 24-5-8*******************************************************************************/#ifndef KINGBASEMANAGERTOOLS_INI_H #define KINGBASEMANAGERTOOLS_INI_H#include iostream #include fstream #include sstream #include map #include string#include set #include filesystem#include boost/property_tree/ptree.hpp #include boost/property_tree/ini_parser.hpp #include boost/filesystem.hppusing namespace std;namespace Circle {class ini {protected:string config_path;setstring* keys nullptr;mapstring, string* props nullptr;void trim(string s);vectorstring split(const string str, char pattern);private:public:ini();virtual ~ini();void file(boost::filesystem::path path);bool is_exists();bool load(std::string defaultValue);bool load(){return load(None);};setstring* getKeys() const;mapstd::string, string *const getProps() const;string getValue(const string key,const string defaultValue);string setValue(const string key,const string Value);bool save();};} // Circle#endif //KINGBASEMANAGERTOOLS_INI_Hini.cpp /********************************************************************************* file : ini.cpp* author : CircleDBA* mail : weiyuanquankingbase.com.cn* blog : circle-dba.blog.csdn.net* date : 24-5-8*******************************************************************************/#include ini.hnamespace fs boost::filesystem;namespace Circle {Circle::ini::ini() {this-props new mapstring, string;this-keys new setstring();}Circle::ini::~ini() {delete props;delete keys;}void Circle::ini::file(boost::filesystem::path path){this-config_path path.string();}bool Circle::ini::is_exists(){return fs::exists(this-config_path);}void Circle::ini::trim(string s){if (!s.empty()){s.erase(0, s.find_first_not_of( ));s.erase(s.find_last_not_of( ) 1);}}vectorstring Circle::ini::split(const string str, char pattern){vectorstring res;stringstream input(str);string temp;while (getline(input, temp, pattern)){res.push_back(temp);}return res;}bool Circle::ini::load(std::string defaultValue None){std::ifstream file(this-config_path);std::string line, key, value, section;while (getline(file, line)) {trim(line);//去空行if (line.empty() || line \r || line[0] #){continue;}int s_startpos, s_endpos;if (((s_startpos line.find([)) ! -1) ((s_endpos line.find(]))) ! -1){section line.substr(s_startpos 1, s_endpos - 1);continue;}//处理等号后为空的配置vectorstring res split(line, );if (res.size() 2){res[1] defaultValue;}int t res[1].find(#);if (t ! string::npos) {res[1].erase(t);}for_each(res.begin(), res.end(), [](string s)mutable {trim(s);});props-insert(make_pair(section.res[0],res[1]));keys-insert(section);}file.close();return true;}setstring* Circle::ini::getKeys() const {return keys;}mapstd::string, string *const Circle::ini::getProps() const {return this-props;}string Circle::ini::getValue(const string key,const string defaultValue) {if (props-find(key) props-end()){return defaultValue;}string value this-props-at(key);return value;}string Circle::ini::setValue(const string key,const string Value) {if (props-find(key) props-end()){this-props-insert(make_pair(key, Value));}else{props-at(key) Value;}return this-props-at(key);}bool Circle::ini::save(){std::ofstream outFile(this-config_path);setstring* keysMap getKeys();for (std::setstring::const_iterator it keysMap-begin(); it ! keysMap-end(); it) {outFile [ *it ] std::endl;for (const auto pair: *props) {vectorstring res split(pair.first,.);if(res[0] *it){outFile res[1] pair.second std::endl;}};}return true;} } // Circleconfig.conf [group1] IP 192.168.30.1 name group1 port 7000 [group2] IP 192.168.1.101 name group2 port 7002mian.cpp /********************************************************************************* file : Application.h* author : CircleDBA* mail : weiyuanquankingbase.com.cn* blog : circle-dba.blog.csdn.net* date : 24-5-6*******************************************************************************/#ifndef KINGBASEMANAGERTOOLS_APPLICATION_H #define KINGBASEMANAGERTOOLS_APPLICATION_H #include iostream #include boost/filesystem.hpp #include src/path/path.h #include src/config/ini.hnamespace Circle {class Application {protected:private:public:boost::filesystem::path RootPath,ConfigPath,DefaultConfigPath;Circle::path* Path;Application() {RootPath Path-ApplictionPath();ConfigPath RootPath / config;DefaultConfigPath RootPath / include / Application / config;boost::filesystem::path config DefaultConfigPath / config.conf;std::cout -------------------------------- start std::endl;Circle::ini ini;ini.file(config);if(ini.is_exists()){ini.load();std::cout ini.getValue(group1.IP,192.168.30.1) std::endl;std::cout ini.setValue(group1.IP,192.168.30.1) std::endl;ini.save();std::cout --------------------------------for start std::endl;mapstring, string* dataMap ini.getProps();for (const auto pair : *dataMap) {std::cout pair.first pair.second std::endl;};}std::cout -------------------------------- end std::endl;}};} // Application#endif //KINGBASEMANAGERTOOLS_APPLICATION_H
http://www.dnsts.com.cn/news/71918.html

相关文章:

  • dedecms wap网站模板下载石家庄市工程勘察设计咨询业协会
  • 广西工程建设质量管理协会网站wordpress图片收费
  • 建设做网站做网站百度收录
  • 本地主机做网站服务器广州网站建设网站托管运营
  • 网站降权是什么意思个人网页设计模板html代码
  • 资阳市网站seo杭州软件定制开发app
  • 如何新做的网站让百度快速收录类似于凡科的网站
  • 建立网站步骤加强 网站群建设管理
  • pc网站生成手机网站网站排名张家港
  • 网站建设推广销售好做吗正规的专业高端网站建设
  • 电商设计师联盟网站seo培训课程
  • 无锡网站建设哪里好杨凌企业网站建设
  • 成都分想设计公司网站网站会员收费怎么做
  • 一个网站建设都需要什么南昌响应式网站建设
  • 创新的菏泽网站建设室内设计网站界面
  • 企业网站管理系统安装教程阿里云里面网站建设
  • 登录wordpress的网址织梦做的网站好优化
  • 怎样建设相亲网站php开源网站管理系统
  • 网站建设公司新好的企业管理网站
  • 少儿编程免费网站建立网站建设考核激励制度
  • 南城网站建设公司信息wordpress主题中的文件
  • 网站开发与维护是什么网站建设几个文件夹
  • 永州市住房和城乡建设厅网站望野思想感情
  • 傻瓜式网站模板深圳尼高网站建设
  • 武昌网站建设价格多少wordpress变化
  • 德阳百度网站建设谷歌优化师
  • h5视频网站模板湖南招聘信息网官网
  • 磁力网站怎么做的源码欢迎访问中国建设银行
  • 网站建设需要哪些材料邢台网站推广多少钱
  • 点开图片跳到网站怎么做重庆平台网站推广