473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

streams again

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.
Sep 2 '09 #1
6 1330
Banfa
9,065 Expert Mod 8TB
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.
Sep 3 '09 #2
weaknessforcats
9,208 Expert Mod 8TB
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.
Sep 3 '09 #3
ya but when we include iostream and do some output of int data type how come it works?
Sep 3 '09 #4
mac11
256 100+
As Banfa said, the stream converts types for you.

When you do, for instance:

cout << 5;
What prints is the text string "5", which is ascii or unicode or whatever to represent the character 5 as TEXT. It does not send the actual value 5 - if it did you would see some nonprintable character rather than a nice 5. The stream is smart and when you send it an int it converts it to text.

If you want to dump raw binary representation of an int you can do that, but it's usually not what you want.
Sep 3 '09 #5
weaknessforcats
9,208 Expert Mod 8TB
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?
Sep 3 '09 #6
ok.thats good.now i get it.
Sep 3 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ronald Legere | last post by:
The new itertools stuff is pretty cool. One thing that bothers me though is that there seems to be no way to copy an iterator. How does one work around this? Is there a trick that I am missing? ...
5
by: ferran | last post by:
Hi, I'm trying to convert a string to a long double using streams but for some reasing seems to give the wrong values, the idea is to do a precise textual conversion without roundings or...
8
by: grahamo | last post by:
Hi, I have written an app that uses streams in a very standard way. I make use of some legacy code something like this; // legacy operator<< , standard enough. ostream&...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
11
by: Kobu | last post by:
I have a question about C's abstract "streams" (that I can't seem to FULLY understand from reading several tutorials). Streams seems to suggest that input can be treated continously if needed....
2
by: bonk | last post by:
Hello how do I connect streams in c# ? Imagine the followung scenario: I have a StreamWriter that writes Text to a Stream. How can I tell that Stream to pass that Data to another Stream...
3
by: _TR | last post by:
I love C# and I've been porting a lot of my older C++ code, but there is one app that I haven't quite figured out yet. I suppose I could re-engineer the app from the ground up, but I've already...
1
by: Chris | last post by:
I'm reading up on streams and I have two articles that seem to conflict with each other. One article describes streams and lists a few of the major ones (FileStream, Memory Stream, Network...
2
by: Abhishek | last post by:
what are the STDUPDATE, STDERR, STDOUT and STDIN streams and how does one access these streams in C language. I am aware of the function fprintf(FILE *fp, char * format, char *s) which puts the...
3
by: Kirit Sælensminde | last post by:
>From thread http://groups.google.com/group/comp.lang.c++/browse_thread/thread/79d767efa42df516 "P.J. Plauger" <p...@dinkumware.comwrites: I'll take this at face value and I'll have to suppose...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.