Advertisement
35657

Untitled

Apr 23rd, 2024
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <Windows.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11.  
  12.     SetConsoleCP(1251);
  13.     SetConsoleOutputCP(1251);
  14.  
  15.     ifstream fin;
  16.     fin.open("file.txt");
  17.  
  18.     ofstream fout;
  19.     fout.open("temp.txt");
  20.  
  21.     if (!fin.is_open() || !fout.is_open()) {
  22.         cout << "Ошибка открытия файла" << endl;
  23.     }
  24.     else {
  25.         // 1 вариант
  26.         char ch;
  27.         while (fin.get(ch)) {
  28.             if (ch >= 'А' && ch <= 'Я') {
  29.                 ch += 32;
  30.             }
  31.             fout << ch;
  32.         }
  33.  
  34.         // 2 вариант
  35.        /* string str;
  36.         while (getline(fin, str)) {
  37.             for (int i = 0; i < str.size(); i++) {
  38.                 if (str[i] >= 'А' && str[i] <= 'Я') {
  39.                     str[i] += 32;
  40.                 }
  41.             }
  42.             fout << str << endl;
  43.         }*/
  44.  
  45.         fin.close();
  46.         fout.close();
  47.         remove("file.txt");
  48.         rename("temp.txt", "file.txt");
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement