Advertisement
SomniP

Читает и копирует в новый файл символы в инвертированном рег

Dec 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <cctype>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     SetConsoleCP(1251);
  14.     SetConsoleOutputCP(1251);
  15.     setlocale(LC_ALL, "rus");
  16.     system("color 0A");
  17.  
  18.     cout << "Введите полное имя файла (путь + имя)" << endl;
  19.     string s;
  20.     getline(cin, s);
  21.     ifstream fin(s);
  22.     size_t del = 0u;
  23.     for (size_t u = 0u; u < s.size(); ++u)
  24.     {
  25.         if (s[u] == '\\')
  26.         {
  27.             del = u;
  28.         }
  29.     }
  30.     s.erase(s.begin() + del + 1u, s.end());
  31.    
  32.     vector<string> box;
  33.     for (;fin.good();)
  34.     {
  35.         string str;
  36.         fin >> str;
  37.         box.push_back(str);
  38.     }
  39.     fin.close();
  40.     vector<string> box2;
  41.     for (const auto &str : box)
  42.     {
  43.         string rez;
  44.         for (const auto &c : str)
  45.         {
  46.             auto cc = static_cast<unsigned char>(c);
  47.             if (toupper(cc) == cc)
  48.             {
  49.                 rez.push_back(tolower(cc));
  50.             }
  51.             else
  52.             {
  53.                 rez.push_back(toupper(cc));
  54.             }
  55.         }
  56.         box2.push_back(rez);
  57.     }
  58.     ofstream fout(s + "output.txt");
  59.     for (const auto &str : box2)
  60.     {
  61.         fout << str << endl;
  62.     }
  63.     fout.close();
  64.  
  65.     system("pause");
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement