Advertisement
35657

Untitled

May 24th, 2024
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. #include <Windows.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. int main() {
  12.     SetConsoleCP(1251);
  13.     SetConsoleOutputCP(1251);
  14.  
  15.     ifstream fin;
  16.     ofstream fout;
  17.  
  18.     fin.open("file.txt");
  19.     fout.open("file2.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.         fin.close();
  36.         fout.close();
  37.         remove("file.txt");
  38.         rename("file2.txt", "file.txt");
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement