解析配置文件的一段练习代码
#include <iostream>
#include <fstream>
#include <cassert>
#include <string>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const string fileName = "config.txt";
map<string, string> tar_path;
int main()
{
ifstream fin;
fin.open(fileName);
if (false == fin.is_open()) {
std::cerr << "open file failed!!" << std::endl;
return -1;
}
string s;
while (getline(fin, s))
{
size_t pos= s.find_first_of("=");
if (pos == std::string::npos || pos+1>=s.size())
continue;
string targetName = s.substr(0,pos-1);
string path = s.substr(pos+1);
std::cout << targetName << " = " << path << std::endl;
}
fin.close();
//================================================
return 0;
}
解析文本为 XXXX=E:\test\1234
作 者: itdef
欢迎转帖 请保持文本完整并注明出处
技术博客 http://www.cnblogs.com/itdef/
B站算法视频题解
https://space.bilibili.com/18508846
qq 151435887
gitee https://gitee.com/def/
欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
如果觉得不错,欢迎点赞,你的鼓励就是我的动力
欢迎转帖 请保持文本完整并注明出处
技术博客 http://www.cnblogs.com/itdef/
B站算法视频题解
https://space.bilibili.com/18508846
qq 151435887
gitee https://gitee.com/def/
欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
如果觉得不错,欢迎点赞,你的鼓励就是我的动力
浙公网安备 33010602011771号