473,569 Members | 2,752 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 1257
On Sep 30, 12:28 am, john <j...@no.spamwr ote:
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 objektorientier ter Datenverarbeitu ng
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
1359
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
17543
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
5900
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 passing the stream to create an XPathDocument object. Thanks rizlaroller
0
3495
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 data from the transport connection.". I'm posting the code, so if somebody can help I'll be very grateful. private void DoListen() {
7
97977
by: Randy | last post by:
Hello, Is there an easy way to convert a string to a stream? Thanks
12
2853
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 text into a stream in order to be able to use DataSetOutcomes1.ReadXML(MyStream). Thanks in advance, James
5
2661
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 by web method in my Web Form application? I already configurated web.config of my web service by running WSE 3.0 setting tool. Thanks!
16
2210
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 **************************************************************** pair_status/myPair
33
2033
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: // ... bool good() const; // next operation might succeed bool eof() const; // end of input seen
0
2879
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 ?myResp.GetResponseStream() {System.Net.ConnectStream}
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.