Reputation: 10998
I've seen code written like so:
ifstream fin;
fin.open("largefile.dat", ifstream::binary | ifstream::in);
Now this makes me confused, is there any difference at all between the above code and this code below using ios::binary
and ios::in
as replacement?
ifstream fin;
fin.open("largefile.dat", ios::binary | ios::in);
Upvotes: 4
Views: 500
Reputation: 6467
From Josuttis N.M. - The Standard Library A Tutorial and Reference.
Chapter 15.2 Fundamental Stream Classes and Stream Objects
The stream classes of the IOStream library form a hierarchy:
The classes in this class hierarchy play the following roles:
1. The base classios_base
defines the properties of all stream classes independent of the character type and the corresponding character traits. Most of this class consists of components and functions for state and format flags.
2. The class templatebasic_ios<>
is derived fromios_base
and defines the common properties of all stream classes that depend on the character types and the corresponding character traits. These properties include the definition of the buffer used by the stream. The buffer is an object of a class derived from the template classbasic_streambuf<>
with the corresponding template instantiation. It performs the actual reading and/or writing.
3. The class templatesbasic_istream<>
andbasic_ostream<>
derive virtually frombasic_ios<>
and define objects that can be used for reading or writing, respectively. Likebasic_ios<>
, these classes are templates that are parametrized with a character type and its traits. When internationalization does not matter, the corresponding instantiations for the character type char —istream
andostream
— are used.
4. The class templatebasic_iostream<>
derives from bothbasic_istream<>
andbasic_ostream<>
. This class template defines objects that can be used for both reading and writing.
5. The class templatebasic_streambuf<>
is the heart of the IOStream library. This class defines the interface to all representations that can be written to or read from by streams and is used by the other stream classes to perform the reading and writing of characters. For access to some external representation, classes are derived frombasic_streambuf<>
.
Upvotes: 2
Reputation: 96810
There's no difference. These names are inherited from the virtual base std::ios_base
from which the concrete stream classes derive.
Upvotes: 7