Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <Windows.h>
- using namespace std;
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- ifstream fin;
- ofstream fout;
- fin.open("file.txt");
- fout.open("file2.txt");
- if (!fin.is_open() || !fout.is_open()) {
- cout << "Ошибка открытия файла" << endl;
- }
- else {
- int del; // номер удаляемой строки
- cout << "Введите номер строки для удаления: ";
- cin >> del;
- int current = 1; // номер текущей строки
- string str;
- while (!fin.eof()) {
- getline(fin, str);
- if (current != del) {
- fout << str << endl;
- }
- current++;
- }
- fin.close();
- fout.close();
- remove("file.txt");
- rename("file2.txt", "file.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement