-4

According to my test in vs2019, ostream takes 72 bytes, istream takes 80 bytes and iostream takes 88 bytes. There is no discernible difference in their size, so I don't think 'it's aimed at saving resource' is right.

Another confusing problem is why istringstream enables construction with std::ios::out?

Waqar
  • 8,558
  • 4
  • 35
  • 43

2 Answers2

2

The openmode for a stream is a bitmask type. I.e. it's a set of bits that you can use bitwise OR to add into a more complex set of flags.

The openmode flags for the string-streams are passed on to the underlying string buffer which is bidirectional.

Passing the flag std::ios::out when creating or opening an input-only stream is just silently ignored.


And the size of an object or a class is in almost all cases irrelevant, and comparing the sizes of unrelated objects (even in the same inheritance hierarchy) often have no meaning.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
0

You need to be able to read and write to the standard input/output streams, and it is also a standard.

Why would you #include <istream> and #include <ostream>. It makes sense to just #include <iostream>.

appledoes
  • 113
  • 9