...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The File concept abstracts access to files in the underlying file system. To support other platform interfaces, users may author their own File types which meet these requirements.
In this table:
F
is a File
type
f
is an instance of
F
p
is a value of type
char const*
which points to a null terminated utf-8
encoded string.
m
is an instance of
file_mode
n
is a number of bytes,
convertible to std::size_t
o
is a byte offset in
the file, convertible to std::uint64_t
b
is any non-const pointer
to memory
c
is any possibly-const
pointer to memory
ec
is a reference of
type error_code
Table 1.34. Valid expressions
Expression |
Type |
Semantics, Pre/Post-conditions |
---|---|---|
Operation |
Return Type |
Semantics, Pre/Post-conditions |
|
Default constructable |
|
|
Destructible. If |
|
|
|
Returns |
|
If |
|
|
Attempts to open the file at the path specified by |
|
|
|
If |
|
|
If |
|
Attempts to reposition the current file offset to the value |
|
|
|
Attempts to read |
|
|
Attempts to write |
struct File { /** Default constructor There is no open file initially. */ File(); /** Destructor If the file is open it is first closed. */ ~File(); /// Returns `true` if the file is open bool is_open() const; /// Close the file if open void close(error_code& ec); /// Open a file at the given path with the specified mode void open(char const* path, file_mode mode, error_code& ec); /// Return the size of the open file std::uint64_t size(error_code& ec) const; /// Return the current position in the open file std::uint64_t pos(error_code& ec) const; /// Adjust the current position in the open file void seek(std::uint64_t offset, error_code& ec); /// Read from the open file std::size_t read(void* buffer, std::size_t n, error_code& ec) const; /// Write to the open file std::size_t write(void const* buffer, std::size_t n, error_code& ec); };