zoukankan      html  css  js  c++  java
  • 解析配置文件的一段练习代码

    #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: est1234

    作 者: itdef
    欢迎转帖 请保持文本完整并注明出处
    技术博客 http://www.cnblogs.com/itdef/
    B站算法视频题解
    https://space.bilibili.com/18508846
    qq 151435887
    gitee https://gitee.com/def/
    欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
    如果觉得不错,欢迎点赞,你的鼓励就是我的动力
    阿里打赏 微信打赏
  • 相关阅读:
    谷歌机器学习
    Pycharm使用conda安装的环境
    HAN模型理解2
    HAN模型理解1
    RCNN
    深度CNN
    多通道CNN
    TextCNN
    词向量2
    词向量1.md
  • 原文地址:https://www.cnblogs.com/itdef/p/9342900.html
Copyright © 2011-2022 走看看