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