利用指定文件进行参考以进行单词的转换
来源:互联网 发布:金融界免费炒股软件 编辑:程序博客网 时间:2024/06/04 22:08
#include <map>
#include <sstream>
#include <fstream>
#include <iostream>
#include <string>
#include <exception>
using namespace std;
ifstream& openfile(ifstream &in, const string &filename){
in.close();//close in case it was alrady open
in.clear();//clear any existing errors
in.open(filename.c_str());//open the file we were given
//in要么于指定文件绑定起来了,要么处于错误条件状态
return in;//condition state is good if open succeeded
}
int main(int argc, char** argv)
{
map<string, string> trans_map;
string key, value;
ifstream map_file;
if (!openfile(map_file, "transform.txt")){
throw runtime_error("no transformation file");
}
//read the tansformation map and build the map
while (map_file >> key >> value){
trans_map.insert(pair<string, string>(key, value));
}
ifstream input;
if (!openfile(input, "source.txt")){
throw runtime_error("no input file");
}
string line;//hold each line from the input
//read the text to transform it a line at a time
while (getline(input, line)){
istringstream stream(line); //read the line a word at a time
string word;
//读字符串流
bool lineFirst = true;//controls whether a space is printed
while (stream >> word){
//ok:the actual mapwork,this part is the heart of the program
map<string, string>::const_iterator iter = trans_map.find(word);
if (iter != trans_map.end()){
//replace it by the transformation value in the map
word = iter->second;
}
if (lineFirst){
cout << word;
lineFirst = false;
}
else{
cout << " " << word;//print space between words;
}
}
cout << endl;//done with this line of input
}
return 0;
}
0 0
- 利用指定文件进行参考以进行单词的转换
- 利用tensorflow进行单词分类
- 以单词为单位进行的字符串翻转
- 利用map容器进行读入文件并对响应的字符进行转换并输出转换后的字符
- 利用C#进行文件后缀名的更改(以txt与html为例)
- hadoop stream指定输出的part文件个数,并利用mapreduce进行压缩
- 利用ArcGIS对shp文件进行投影转换
- 利用struts1进行多文件的上传
- 利用多线程进行文件的复制
- 利用日期进行文件的创建
- Java利用TCP进行文件的传输
- 利用SecureCRT进行文件的传输
- 利用GitHub进行文件的版本控制
- 利用Struct2进行文件的上传
- 利用FNDLOAD进行ldt文件的下载
- 利用XML文件进行类的反射
- 利用矩阵进行坐标系转换
- 利用堆栈进行数制转换
- PowerShell介绍 第十二回 函数
- 2014-2015 ACM-ICPC, Asia Tokyo Regional Contest A題:Bit String Reordering [bfs]
- 实际案例讲解iOS设计模式——MVC模式
- 安卓开发错误笔记
- Android系统当前时间日期的获取
- 利用指定文件进行参考以进行单词的转换
- Java登录到新浪微博抓取数据
- andriod切换语言,切换时区,重启应用apk
- C#接收C/C++DLL的结构体嵌套数组及多维数组的解决方案
- Android提高第四篇之Activity+Intent
- VMware中ubuntu忘记密码的解决办法
- 实战解析Android架构设计原则
- qq链接
- Java设计模式_观察者模式&事件处理机制