Advertisement
35657

Untitled

Apr 20th, 2024
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 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.         int del;
  26.         cout << "Какую строку будем удалять: ";
  27.         cin >> del;
  28.         int current = 1;
  29.         string str;
  30.         while (!fin.eof()) {
  31.             getline(fin, str);
  32.             if (current != del) {
  33.                 fout << str << endl;
  34.             }
  35.             current++;
  36.         }
  37.         fin.close();
  38.         fout.close();
  39.         remove("file.txt");
  40.         rename("temp.txt", "file.txt");
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement