Advertisement
35657

Untitled

Apr 18th, 2024
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     ofstream fout; // создали объект класса fstream
  9.  
  10.     fout.open("file.txt"); // открываем существующий файл в рабочем каталоге программы или создаем при его отсутствии
  11.  
  12.     if (!fout.is_open()) { // проверка успешности открытия файла
  13.         cout << "Ошибка открытия файла" << endl;
  14.     }
  15.     else {
  16.         fout << "Привет" << endl << 1111 << endl;
  17.         fout.close(); // закрываем файл (освобождаем ресурсы)
  18.     }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement