用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; }