一个单词转换的map
2017-07-25 19:04
246 查看
单词转换文件的内容
brb be right back
k okay?
y why
r are
u you
pic picture
rhk thanks!
18r later
我们希望转换的文本
where r u
y dont u send me a pic
k thk 18r
brb
brb
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<set>
#include<algorithm>
#include<fstream>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int main()
{
ifstream inFile("C:\\Users\\DELL\\Desktop\\input.txt", ios::in);
if (inFile.fail()){
cout << "inFile failed" << endl;
system("pause");
exit(0);
}
map<string, string> Trans;
string line, TransB, TransA;
while (inFile>>TransB && getline(inFile, TransA)){
TransA = TransA.substr(1);
Trans.insert(make_pair(TransB, TransA));
}
inFile.close();
ifstream inFile1("C:\\Users\\DELL\\Desktop\\input1.txt", ios::in);
if (inFile1.fail()){
cout << "inFile1 failed" << endl;
system("pause");
exit(0);
}
ofstream outFile("C:\\Users\\DELL\\Desktop\\output.doc",ios::app );
while (getline(inFile1, line)){
string a;
istringstream In(line);
while (In >> a){
auto it = Trans.find(a);
if (it == Trans.end()){
outFile << a << " ";
}
else{
outFile << Trans[a] << " ";
}
}
outFile << endl;
}
inFile1.close();
outFile.close();
system("pause");
return 0;
}
brb be right back
k okay?
y why
r are
u you
pic picture
rhk thanks!
18r later
我们希望转换的文本
where r u
y dont u send me a pic
k thk 18r
brb
brb
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<set>
#include<algorithm>
#include<fstream>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int main()
{
ifstream inFile("C:\\Users\\DELL\\Desktop\\input.txt", ios::in);
if (inFile.fail()){
cout << "inFile failed" << endl;
system("pause");
exit(0);
}
map<string, string> Trans;
string line, TransB, TransA;
while (inFile>>TransB && getline(inFile, TransA)){
TransA = TransA.substr(1);
Trans.insert(make_pair(TransB, TransA));
}
inFile.close();
ifstream inFile1("C:\\Users\\DELL\\Desktop\\input1.txt", ios::in);
if (inFile1.fail()){
cout << "inFile1 failed" << endl;
system("pause");
exit(0);
}
ofstream outFile("C:\\Users\\DELL\\Desktop\\output.doc",ios::app );
while (getline(inFile1, line)){
string a;
istringstream In(line);
while (In >> a){
auto it = Trans.find(a);
if (it == Trans.end()){
outFile << a << " ";
}
else{
outFile << Trans[a] << " ";
}
}
outFile << endl;
}
inFile1.close();
outFile.close();
system("pause");
return 0;
}
相关文章推荐
- C++ Primer : 第十一章 : 关联容器示例: 一个单词转换的map
- P391--一个单词转换的map
- c++ primer 一个单词转换的map(自定义版)
- C++Primer第11章 一个单词转换的map【程序】
- C++中map容器实现单词转换的程序
- 一个简单的例子理解C++ map, 运用map统计单词出现的次数
- map——单词的转换
- c++学习笔记——个单词转换的map程序详解
- 单词转换(map对象)
- 单词转换程序——使用map&文件读写操作
- 如何将一个map结构的数据转换成JSON结构的数据
- C++ primer ————————————“单词转换" map 对象
- 利用map和reduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456
- C++STL--map和set 词频统计和单词转换
- 给定两个有着相同长度且都在字典内的单词,要求写一个方法来把一个单词变型成另一个单词。 一次只能转换一个字母,且每次生成的单词必须在字典内
- c++学习笔记-map的使用实例(单词转换)
- 【Java工具】将一个对象转换成Map
- c++primer关联容器中的“单词转换map程序”分析
- 10.3.9例子“单词转换”map对象
- 分享一个map跟javabean转换的方法