C++输入输出流迭代器 map
2009-08-03 13:25
148 查看
用map将text2中的文件内容用text1中的转换方式转换存储在text3中
//text1.txt 'em them cuz because gratz grateful i I nah no pos supposed sez said tanx thanks wuz was
//text2.txt nah i sez tanx cuz i wuz pos to not cuz i wuz gratz
//text3.txt no I said thanks because I was supposed to not because I was grateful
#include<iostream> #include<map> #include<string> #include<fstream> #include<sstream> #include<iterator> using namespace std; int main() { map<string,string> m; string str,str1,str2,s; ifstream inTextOne("text1.txt"); while(getline(inTextOne,str)) { inTextOne>>str1>>str2; m[str1]=str2; } inTextOne.close(); ifstream inTextTwo("text2.txt"); ofstream outText("text3.txt"); while(getline(inTextTwo,str)) { map<string,string>::iterator it; bool trueFirst=false; istringstream sin(str); istream_iterator<string> begin(sin); istream_iterator<string> end; ostream_iterator<string> out(outText); while(begin!=end) { if(trueFirst) *out++=" "; trueFirst=true; it=m.find(*begin); if(it!=m.end()) *out++=it->second; else *out++=*begin; begin++; } *out++="/n"; } inTextTwo.close(); outText.close(); return 0; }
相关文章推荐
- C++学习之map类型
- C++中map容器的使用说明
- C++中的关联容器map用法
- C++模板类 容器之map及对象副本 深/浅拷贝等问题浅析
- C++学习笔记---再探 map 的用法之计数重复key的value值的方法,由leetcode 169题想到的
- C++小知识之Map用法
- 容器 C++ set和map
- C++中map的常用方法
- C++文本查询程序 C++Primer练习12.28 使用vector,map,set容器保存来自文件的数据并生成查询结果
- C++文本查询程序 C++Primer练习12.28 使用vector,map,set容器保存来自文件的数据并生成查询结果
- C++ map的基本操作
- C++ Map的使用
- C++ map的基本操作和用法
- C++中 vector、list、deque、set、map的底层实现
- C++ map的基本操作和使用
- C++ 映射map的使用心得
- C++ map循环遍历
- c++中pair和map的区别
- c++ stl map<> 容器测试
- C++ Map