ostream& operator<< (ostream&, bool)

Gabriel Dos Reis Gabriel.Dos-Reis@dptmaths.ens-cachan.fr
Mon Apr 13 03:22:00 GMT 1998


>>>>> «BJP», B James Phillippe <bryan@terran.org> écrit :

BJP> On Mon, 13 Apr 1998, Gabriel Dos Reis wrote:
>> cout << (1 == 1) << '\n' << (1 == 2) << '\n';
>> 
>> shouldn't the output be looks like 
>> 
>> true
>> false
>> 
>> instead of
>> 
>> 1
>> 0

BJP> 0 *is* false and 1 *is* true, as far as the machine is concerned.  Printing

Well, I'm not concerned with the machine representation... With the
same reasonning 
	cout << 5;
should output 101 by *default* instead of 5.

BJP> a character string (eg., "true" or "false") is not the same thing as
BJP> printing an integral evaluation; it's equivalent to expecting the string
BJP> "five" or "nineteen" to be used in place of the values '5' and '19'.  There
BJP> are ways to accomplish what you're trying to do without redefining C++.
BJP> One method comes to mind:

BJP> inline const char* boolToString( bool expr ) {
	
BJP> 	return (expr == true) ? "true" : "false";
BJP> }

not necessary: Alexandre gave me the right answer.

BJP> cheers,
BJP> -bp
BJP> --
BJP> B. James Phillippe <bryan@terran.org>
BJP> Linux Software Engineer, WGT Inc.
BJP> http://earth.terran.org/~bryan

-- Gaby
"One reason that life is complex is that it has a 
real part and imaginary part." -- Andrew Koenig



More information about the Gcc mailing list