35657

Untitled

May 28th, 2024
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <map>
  6. #include <Windows.h>
  7.  
  8.  
  9. int main() {
  10.  
  11.     SetConsoleCP(1251);
  12.     SetConsoleOutputCP(1251);
  13.  
  14.     std::ifstream fin("eng-rus dictionary.txt");
  15.  
  16.     std::ofstream fout("rus-eng dictionary.txt");
  17.  
  18.     if (!fin.is_open() || !fout.is_open()) {
  19.         std::cout << "Ошибка открытия файла" << std::endl;
  20.     }
  21.     else {
  22.         std::string word, translation;
  23.  
  24.         std::map<std::string, std::string> dictionary;
  25.  
  26.  
  27.         // чтобы не считывал пустые строки в конце
  28.         fin >> word >> translation;
  29.         while (!fin.eof()) {
  30.             dictionary[translation] = word;
  31.             fin >> word >> translation;
  32.         }
  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