2023年7月7日发(作者:)
c++读取配置⽂件⽅法⼀。消息头⽂件内容如下:// stdafx.h : 标准系统包含⽂件的包含⽂件,// 或是经常使⽤但不常更改的// 特定于项⽬的包含⽂件//#pragma once#include "targetver.h"#include
#include
#define COMMENT_CHAR '#'
bool ReadConfig(const string & filename, map
start_pos = i;
for (i = () - 1; i >= 0; --i) { if (!IsSpace(str[i])) { break; } } end_pos = i;
str = (start_pos, end_pos - start_pos + 1);}bool AnalyseLine(const string & line, string & key, string & value){ if (()) return false; int start_pos = 0, end_pos = () - 1, pos; if ((pos = (COMMENT_CHAR)) != -1) { if (0 == pos) { // ⾏的第⼀个字符就是注释字符 return false; } end_pos = pos - 1; } string new_line = (start_pos, start_pos + 1 - end_pos); // 预处理,删除注释部分
if ((pos = new_('=')) == -1) return false; // 没有=号
key = new_(0, pos); value = new_(pos + 1, end_pos + 1- (pos + 1));
Trim(key); if (()) { return false; } Trim(value); return true;}bool ReadConfig(const string & filename, map
(); return true;}void PrintConfig(const map
system("pause"); return 0;}三。 配置⽂件名称为 内容如下:root = etcconfig = etc/profile
ProGroupName = branchreceive
四。执⾏结果截图
发布者:admin,转转请注明出处:http://www.yc00.com/news/1688702185a163774.html
评论列表(0条)