/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/cpp/cpp-506-21-001/main.cpp
28 строк
581 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
#include <fcntl.h> #include <stdexcept> #include <string> #include <unistd.h> class FileDescriptor { public: explicit FileDescriptor(const std::string& path) { fd_ = ::open(path.c_str(), O_RDONLY); if (fd_ == -1) { throw std::runtime_error("open failed"); } } ~FileDescriptor() { if (fd_ != -1) { ::close(fd_); } } FileDescriptor(const FileDescriptor&) = delete; FileDescriptor& operator=(const FileDescriptor&) = delete; int get() const { return fd_; } private: int fd_ = -1; };