35657

Untitled

Sep 3rd, 2023
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <Windows.h>
  6. #include <fstream>
  7. #include <map>
  8.  
  9.  
  10.  
  11. int main() {
  12.  
  13.     SetConsoleCP(1251);
  14.     SetConsoleOutputCP(1251);
  15.  
  16.     std::ifstream fin;
  17.     fin.open("eng-rus dictionary.txt");
  18.  
  19.     std::ofstream fout;
  20.     fout.open("rus-eng dictionary.txt");
  21.  
  22.     if (!fin.is_open() || !fout.is_open()) {
  23.         std::cout << "Ошибка открытия файла" << std::endl;
  24.     }
  25.     else {
  26.         std::string word;
  27.         std::string translation;
  28.         std::map<std::string, std::string> dictionary;
  29.  
  30.         while (!fin.eof()) {
  31.             fin >> word >> translation;
  32.             dictionary[translation] = word;
  33.         }
  34.         for (auto a : dictionary) {
  35.             fout << a.first;
  36.             for (int i = 0; i < 20 - a.first.size(); i++) {
  37.                 fout << " ";
  38.             }
  39.             fout << a.second << std::endl;
  40.         }
  41.         fin.close();
  42.         fout.close();
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment