Advertisement
35657

Untitled

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