C++11: unordered_map
来源:互联网 发布:解方程组软件 编辑:程序博客网 时间:2024/06/05 09:57
#include <unordered_map>#include <fstream>#include <iostream>#include <string>#include <sstream>void word_transform(std::ifstream &map_file, std::ifstream &input);std::unordered_map<std::string, std::string> buildUnorderedmap(std::ifstream &map_file);const std::string& transform(const std::string &s, const std::unordered_map<std::string, std::string> &m);int main(){ std::ifstream rule("rules.txt"); std::ifstream text("text.txt"); word_transform(rule, text); return 0;}void word_transform(std::ifstream &map_file, std::ifstream &input){ auto trans_map = buildUnorderedmap(map_file); std::string text; while (std::getline(input, text)) { std::istringstream stream(text); std::string word; bool firstword = true; while (stream >> word) { if (firstword) { firstword = false; } else { std::cout << " "; } std::cout << transform(word, trans_map); } std::cout << std::endl; }}std::unordered_map<std::string, std::string> buildUnorderedmap(std::ifstream &map_file){ std::unordered_map<std::string, std::string> trans_map; std::string key; std::string value; while (map_file >> key && std::getline(map_file, value)) { if (value.size() > 1) { trans_map.insert({key, value.substr(1)}); } } return trans_map;}const std::string& transform(const std::string &s, const std::unordered_map<std::string, std::string> &m){ auto map_it = m.find(s); if (map_it != m.end()) { return map_it->second; } else { return s; }}
// from C++ primer 5th exercise 11.38(p.446)// g++ xx.cpp -std=c++11
0 0
- c++: unordered_map
- C++unordered_map使用例子
- 【c++】unordered_set和unordered_map
- C++11: unordered_map
- unordered_map
- unordered_map
- unordered_map
- unordered_map
- unordered_map -
- unordered_map
- unordered_map
- unordered_map
- unordered_map
- unordered_map
- 【C++】boost库中的unordered_map和unordered_set
- (C++)unordered_map 与 map 的对比
- c++11新特性:unordered_map
- c++11 无序map unordered_map
- MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法
- 一片不错的V4L2
- Kinect for Windows SDK开发学习相关资源
- Nginx
- 第三讲:React Native & HTML5+(学习笔记1)
- C++11: unordered_map
- Xib学习总结
- apache二级域名绑定到目录
- 使用密钥ssh登录到主机
- Ping值和带宽之间关系
- Windows memcached 安装 window7 64位(亲试)
- 概率统计的基本知识
- 2016CSDN前十排名博客地址
- Oracle分析函数——函数RANK,DENSE_RANK,FIRST,LAST…