we say that iostream is a class template specialization for char i/o for C++ standard library class basic_iostream then why does it also does i/o other than char type.
streams again
Collapse
X
-
Tags: None
-
The char refers to the data type of the output (or input) stream. A stream is a long series of values and each value has a type. For a char stream each value has type char but (in theory) you can have a stream of any type.
The classes convert from the stream to the type that you are interested in inputing/outputing. -
You can use basic_iostream< char> if you want. iostream s just a typedef of this.
You can also use basic_iostream< wchar_t>. This is typedef'd to wiostream.
char and wchar_t are the only types you can use with basic_iostream.Comment
-
-
As Banfa said, the stream converts types for you.
When you do, for instance:
cout << 5;
If you want to dump raw binary representation of an int you can do that, but it's usually not what you want.Comment
-
a basic_iostream< int, etc...> requires a traits class. Int that traits class there is a char_type and an int_type. The char_type is the type used for the stream width and the int_type is an integer that can represent any valus of char_type plus the end-of-file or EOF character.
Therefore, int_type is larger than char_type.
If your char_type is int, then what is your int_type? Like, have you written a special traits class?Comment
-
Comment