The most important thing to keep in mind whenever we're talking about file I/O is that everything I/O-related in C and C++ is built on top of the POSIX standard. POSIX is a very low-level specification, almost at the level of Linux system calls, that has quite a bit of overlap with the C and C++ standards for I/O; and, if you don't understand the gist of the POSIX layer, you'll have a very hard time understanding the concepts that come later.
Bear in mind that technically, none of what follows is standard C++! It is, rather, valid C++ that conforms to a non-C++ standard: the POSIX standard. In practice, this means that it'll work on any operating system except Windows, and may even work on modern Windows systems via the Windows Subsystem for Linux (WSL). Regardless, all the standard APIs (both <stdio.h> and <iostream>) are built...