Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <istream>
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <map>
- #include <cstring>
- using namespace std;
- class change {
- public:
- change() {}
- void operator() (pair<string, string> list) {
- cout « list.first « " -> " « list.second « endl;
- }
- };
- int main() {
- ifstream inFile1("zamena.txt");
- ifstream inFile2("text.txt");
- ofstream outFile("OutFile.txt");
- if (!inFile1 || !inFile2 || !outFile) {
- cerr « "ERROR: can't open stream" « endl
- « "Can't find files" « endl;
- }
- map<string, string> mapp;
- map<string, string>::iterator itmapp;
- string key;
- string value;
- while (!inFile1.eof()) {
- inFile1 » key;
- inFile1 » value;
- mapp[key] = value;
- }
- for_each(mapp.begin(), mapp.end(), change());
- string buf;
- int len;
- char p;
- while (!inFile2.eof()) {
- if (getline == "\n")
- outFile « '\n';
- inFile2 » buf;
- //cout « buf « endl;
- len = strlen(buf);
- if ((buf[len] == '.') || (buf[len] == '!') ||
- (buf[len] == '?') || (buf[len] == ',')) {
- p = buf[len];
- //cout « p « endl;
- buf[len] = "\0";
- //cout « buf « endl;
- if ((itmapp = mapp.find(buf)) != mapp.end()) {
- outFile « itmapp->second « p « " ";
- } else
- outFile « buf « p « " ";
- } else {
- if ((itmapp = mapp.find(buf)) != mapp.end()) {
- outFile « itmapp->second « " ";
- } else
- outFile « buf « " ";
- }
- }
- inFile1.close();
- inFile2.close();
- outFile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement