//实现你自己版本的单词转换程序
#include<iostream>
#include<map>
#include<sstream>
#include<fstream>
using namespace std;
void my_word_transform(ifstream &map_file,ifstream &input);
map<string,string> my_build_map(ifstream &map_file);
const string& my_transform(const string &s,const map<string,string> &m);
int main(int argc,char *argv[]){
ifstream in1(argv[1]),in2(argv[2]);
my_word_transform(in1,in2);
system("pause");
}
void my_word_transform(ifstream &map_file,ifstream &input){
auto my_map=my_build_map(map_file);
string text;//du qu mei hang shu ru
while(getline(input,text)){
istringstream stream(text);
string word;
bool first_word=true;
while(stream>>word){
if(first_word)
first_word=false;
else
cout<<' ';
cout<<my_transform(word,my_map);}
cout<<endl;
}
}
map<string,string> my_build_map(ifstream &map_file){
map<string,string> my_map;
string key;
string value;
while(map_file>>key&&getline(map_file,value)){
my_map[key]=value.substr(1);
}
return my_map;
}
const string& my_transform(const string &s,const map<string,string> &m){
auto find=m.find(s);
if(find!=m.end())
return find->second;
else
return s;
}
c++primer练习11.33
最新推荐文章于 2020-02-27 21:18:39 发布