单词转换
来源:互联网 发布:保险公司客户储存软件 编辑:程序博客网 时间:2024/04/30 14:08
单词转换文件:
测试文件:
结果:
源代码:
#include<iostream>#include<fstream>#include<sstream>#include<map>using namespace std;int main(void){ ifstream file; //单词对应 ifstream test; //测试用例 file.open("file.txt",ios::in); test.open("test.txt",ios::in); if(!file) { cout<<"file not found or file can't open"<<endl; } if(!test) { cout<<"test not found or test can't open"<<endl; } string key,value; //键值对 map<string,string> m; //map存贮 while(file>>key>>value) { m.insert(make_pair(key,value)); //存入map } string line; string word; bool isFirst; map<string,string>::const_iterator it; while(getline(test,line)) //每次读入一行 { istringstream iss(line); //读取每个单词 isFirst=true; while(iss>>word) { if((it=m.find(word))!=m.end()) //查找是否存在 { word=it->second; } if(isFirst) //如果是第一个 { isFirst=false; } else //如果不是第一个 { cout<<' '; } cout<<word; } cout<<endl; } file.close(); test.close(); return 0;}
- 单词转换
- 单词转换(stl map)
- C++ 单词转换例子
- 单词首字母转换大小写
- c++ demo: 单词转换
- 字符串转换为单词,重复单词删除
- 单词转换(map对象)
- 转换每个单词首字母大写
- word中单词大小写转换
- c++ 单词转换 map对象
- 一个单词转换的map
- 在PHP中将数字转换成单词
- 将英文字符串单词首字母转换大写
- 10.3.9例子“单词转换”map对象
- 使用map实现单词转换的程序
- ruby单词单数复数相互转换
- c++ primer 习题之 单词转换程序
- 实现单词转换的小程序
- Hadoop 的学习
- hdu Train Problem I 栈的基本应用
- DELPHI 去掉字符串中的HTML标记,返回纯文本
- selenium web site
- C语言中的"#"和"##"
- 单词转换
- 你要相信没有到不了的明天
- 程序员面试题精选100题(05)-查找最小的k个元素
- 类的作用域问题,形参表函数体处在作用域中,而函数返回类型不一定在作用域中
- 黑马程序员----枚举类的学习笔记
- 线索二叉树
- gdb 基本用法小结
- python_给字典添加条目
- Gcc 参数详解