473,503 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stream state question

In TC++PL 3, on page 616, "class basic_ios" has the public members

"operator void *() const; // nonzero if !fail()
bool operator!() const { return fail(); }"

for using them in conditional statements in the style:

if(cin) // if( !void *(0) )

if(!cin) // if( cin.operator!()
Why isn't operator bool() used instead? For historical reasons?
Sep 29 '07 #1
2 1253
On Sep 30, 12:28 am, john <j...@no.spamwrote:
In TC++PL 3, on page 616, "class basic_ios" has the public members
"operator void *() const; // nonzero if !fail()
bool operator!() const { return fail(); }"
for using them in conditional statements in the style:
if(cin) // if( !void *(0) )
if(!cin) // if( cin.operator!()
Why isn't operator bool() used instead? For historical
reasons?
The most obvious reason is that iostream was part of the
language before bool was. And that bool is an integral type,
which can lead to unexpected results when used with the >and
<< operators.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 1 '07 #2
James Kanze wrote:
>
>Why isn't operator bool() used instead? For historical
reasons?

The most obvious reason is that iostream was part of the
language before bool was. And that bool is an integral type,
which can lead to unexpected results when used with the >and
<< operators.

basic_osstream has explicit "operator<<()" definitions for both "bool"
and "const void *".
Oct 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1357
by: JM | last post by:
Hi, If you change the same string stream to a new string, why is it that you have to .clear() it before using it? If I don't I get garbage. Thanks, Jason ex.
5
17533
by: Sandy | last post by:
Hi, In one of my interview i was asked the difference between Stream and Buffer. can anybody explain the difference. Thanks
4
5899
by: Joe Rizla | last post by:
Is there any example code I can find which shows how to Serialize an object to System.IO.Stream. The reason why is because I want the pass the stream on: The Stream is then XSLT Transformed by...
0
3491
by: Galore | last post by:
Hello, I'm trying to make a simple socket application, something like a chat application, but when I run it, it shows the following error when the client connects to the server: "Unable to read...
7
97974
by: Randy | last post by:
Hello, Is there an easy way to convert a string to a stream? Thanks
12
2844
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the...
5
2656
by: Hardy Wang | last post by:
Hi all, I am new to WSE 3.0, and currently reading the document shipped with installation. From sample provided (see below), I created WSE service side code, but how can I consume stream returned...
16
2204
by: Gary Wessle | last post by:
Hi please help with this. std::fstream iofs( f.c_str(), std::ios::in|std::ios::out ); std::cout << f << '\n' << iofs.is_open() << std::endl; puts out...
33
2016
by: john | last post by:
I am reading TC++PL3 and in "21.3.3 Stream State", 4 member functions returning bool are mentioned: template <class Ch, class Tr= char_traits<Ch class basic_ios: public ios_base { public: //...
0
2860
by: vishnu | last post by:
Hi, Am trying to post the data over https and am getting error in httpwebresponse.getResponseStream.Please help me to get rid of this issue. Here is the message from immediate window ...
0
7202
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
7084
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
7328
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...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.