Why do we use std;:ofstream
for output and std::ifstream
for input if it is possible to use std::fstream
for both?
Asked
Active
Viewed 452 times
0

BenMorel
- 34,448
- 50
- 182
- 322

Miguel Ruiz
- 65
- 2
- 7
-
I think he is asking if you can just use something like `fstream The_Old_In_And_Out;` and have it behave as both an input and output stream – Chemistpp Aug 29 '13 at 17:11
-
@Chemistpp: Wait, that is a valid interpretation of his question too. Darn. Rolling back my edit... – Mooing Duck Aug 29 '13 at 17:12
-
It likely would have taken less effort to simply read [the documentation](http://en.cppreference.com/w/cpp/io/basic_fstream) than go through the trouble of posting here. – WhozCraig Aug 29 '13 at 17:19
-
Sorry, I mean the fstream, ofstream and ifstream library. I can get the ofstream and ifstream clases from the fstream library, right? – Miguel Ruiz Aug 29 '13 at 17:22
1 Answers
2
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).