30 Input/output library [input.output]

30.10 File systems [filesystems]

30.10.34 Filesystem operation functions [fs.op.funcs] File size [fs.op.file_size]

uintmax_t file_size(const path& p); uintmax_t file_size(const path& p, error_code& ec) noexcept;


  • If !exists(p) an error is reported ([fs.err.report]).

  • Otherwise, if is_­regular_­file(p), the size in bytes of the file p resolves to, determined as if by the value of the POSIX stat structure member st_­size obtained as if by POSIX stat().

  • Otherwise, the result is implementation-defined.

The signature with argument ec returns static_­cast<uintmax_­t>(-1) if an error occurs.

Throws: As specified in [fs.err.report].