I\'ve always heard that C++ file I/O operations are much much slower then C style I/O. But I didn\'t find any practical references on comparatively how slow they actually ar
You're using endl to print a newline. That is the problem here, as it does more than just printing a newline — endl also flushes the buffer which is an expensive operation (if you do that in each iteration).
Use \n if you mean so:
file << i << '\n';
And also, must compile your code in release mode (i.e turn on the optimizations).