Yes, the behavior is clearly defined: both functions will go through movements for unformatted I / O functions (building a sentry, setting failbit, if eofbit is installed, clearing the associated stream if necessary), and then they will get to this section:
ยง27.7.2.3 [istream.unformatted] / 30
Symbols are retrieved and stored until the following happens:
- n characters are stored;
ยง27.7.3.7 [ostream.unformatted] / 5
Characters are inserted until the following happens:
- n characters are inserted;
"null characters are saved / inserted" is true before something is saved or retrieved.
Looking at the actual implementations, I see for (; gcount < n; ++gcount) in libC ++ or sgetn(buffer, n); in stdlibC ++ , which has an equivalent loop
Cubbi source share