read is a single iostream setup (part of every iostream operation) and one OS call directly read into the buffer that you provided.
The iterator works by repeatedly extracting one char with operator>> . Due to the size of the buffer, this may mean more OS calls, but, more importantly, it also means reconfiguring and disabling the iostream clock, which can mean locking the mutex and usually means a bunch of other things. In addition, operator>> is a formatted operation, while read unformatted, which is an additional overlay for each operation.
Edit: Tired eyes saw istream_iterator instead of istreambuf_iterator. Of course, istreambuf_iterator does not do formatted input. It calls sbumpc or something similar on streambuf. There are still a lot of calls and the use of a buffer, which is probably smaller than the entire file.
source share