Advertisement
35657

Untitled

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