io::File
A Python-like file object over std::fstream.
RAII closes on scope exit — the C++ analog of with open(...) as f:. Move-only (copying a file handle is meaningless), like Python file objects.
Functions
File · 4 overloads
Construct a closed file (no stream attached).
Leaves the underlying stream default-constructed and unopened, so is_open() is false until a later open(); read/write calls on it are no-ops that fail silently.
O(1).
none.
CheatahIo.FileIsOpenAndCloseIoCompileRun.IsOpenAndCloseStdlibE2E.Iooperator= · 2 overloads
Move-assign, taking over the other handle (the moved-from File becomes closed).
reference to this File.
Close the stream if still open.
O(1).
none.
CheatahIo.FileIsOpenAndCloseIoCompileRun.IsOpenAndCloseStdlibE2E.Io(Re)open path in mode.
Opens the stream on path; it does not first close an already-open handle, so reuse this on a closed File. Mode follows Python: r read, w truncate-write, a append, + adds the opposite direction, b binary; an unrecognized/empty mode defaults to r.
path | filesystem path. |
mode | Python-style mode string. |
O(1) plus the OS open.
none.
CheatahIo.FileWriteThenReadWholeIoCompileRun.OpenWriteReadStdlibE2E.IoIs the underlying stream open?
true iff a file is attached and open.
O(1).
none.
CheatahIo.FileIsOpenAndCloseIoCompileRun.IsOpenAndCloseStdlibE2E.IoClose the underlying stream (no-op if already closed).
O(1).
none.
CheatahIo.FileIsOpenAndCloseIoCompileRun.IsOpenAndCloseStdlibE2E.IoRead the whole remaining file.
Drains the stream buffer from the current position to EOF in one shot, so a prior readline()/read() returns only what is left; returns "" at EOF or on a closed file.
the remaining bytes as one string.
O(n) in bytes read.
allocates the returned string (buffered through a stringstream).
CheatahIo.FileWriteThenReadWholeIoCompileRun.OpenWriteReadStdlibE2E.IoRead the next line.
Consumes through the next \n (which is discarded). Because both a genuine empty line and EOF yield "", the return value alone cannot distinguish them — check is_open()/EOF separately if that matters.
the line with its newline stripped; "" at EOF.
O(line length).
allocates the returned string.
CheatahIo.FileReadlineThenReadlinesIoCompileRun.ReadlineStdlibE2E.IoRead all remaining lines.
Repeatedly getlines from the current position until EOF, pushing each newline-stripped line; returns an empty vector at EOF, and a trailing newline does not produce a final empty element.
a vector of lines (newlines stripped).
O(n) in bytes.
allocates the vector and each line string.
CheatahIo.FileReadlineThenReadlinesIoCompileRun.ReadlinesStdlibE2E.IoWrite a streamable value to the file.
Streams value through operator<< exactly as written — no separator and no trailing newline are added (unlike print()), so the caller supplies any \n; data may stay buffered until the stream is flushed or the File is closed.
value | any streamable value. |
O(output length).
none (writes straight to the stream buffer).
A failed write is not reported: on a closed File or a failed stream the data is silently dropped (only the stream's error state records it) — there is no exception and no return value.
IoCompileRun.OpenWriteReadStdlibE2E.IoMap a Python mode string (r/w/a, optional +/b) to std::ios::openmode.
