Advertisement
35657

Untitled

Apr 23rd, 2024
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 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.         string str;
  26.         while (!fin.eof()) {
  27.             getline(fin, str);
  28.             if (str != "") {
  29.                 fout << str << endl;
  30.             }
  31.         }
  32.  
  33.         fin.close();
  34.         fout.close();
  35.         remove("file.txt");
  36.         rename("temp.txt", "file.txt");
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement