You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
586 B
C++

#ifndef GUARD_RECUMBENTLY_ABRAM_FRAME_MISREGARDS_9196
#define GUARD_RECUMBENTLY_ABRAM_FRAME_MISREGARDS_9196
#pragma once
#include <cstdio>
#include <memory>
#include <stdexcept>
class File
{
public:
File() noexcept = default;
File(FILE* f) noexcept : file{f} {}
File(const char* fname, const char* mode) : file{fopen(fname, mode)}
{ if (!file) throw std::runtime_error("Failed to open file"); }
operator FILE*() noexcept { return file.get(); }
private:
struct Fclose { void operator()(FILE* f) noexcept { fclose(f); } };
std::unique_ptr<FILE, Fclose> file;
};
#endif