Stream operations are extraction <<
and insertion >>
. When you do the following assuming
file
is of fstream
type:
file << 5 << 6.5 << "Hello World!"; // insertion of data (output)
file >> x >> y >> str; // exaction of data (input)
You could also, deal with the stream
as a binary stream
. In that case, it doesn't really look like a "stream
" of data but that gives you random access to the data. In some cases you can't use the binary mode, especially if your data is not available like a network stream. Insertion and Extraction, are the two main operations on streams.
ifstream
is created as an input stream
by default. So, std::ios::in
is redundant in this case. You are using the flags correctly.
all streams inherit from ios
. So, the flags are available in both places, you can either retrieve them from ios
directly or from fstream
.