Search code examples
c++fstreamifstreamofstream

Fstream contain all the content of ofstream and ifstream?


Why do we use std;:ofstream for output and std::ifstream for input if it is possible to use std::fstream for both?


Solution

  • This is the similar case as with stringstream, istringstream and ostringsstream (link).

    Usually you don't both read and write from the same stream, so using ifstream and ofstream is easier as you don't have to bother about the stream state and stream positions (as is the case with fstream).