From: Martin Ambuhl Newsgroups: alt.comp.lang.learn.c-c++,comp.os.msdos.djgpp Subject: Re: boolalpha Date: Wed, 26 May 1999 18:01:03 -0400 Content-Transfer-Encoding: 7bit References: <374B6D9C DOT FE16DE6 AT daidun DOT kaist DOT ac DOT kr> <7ihibj$p5l$1 AT pegasus DOT csx DOT cam DOT ac DOT uk> X-Posted-Path-Was: not-for-mail X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-ELN-Date: 26 May 1999 21:59:51 GMT X-ELN-Insert-Date: Wed May 26 15:05:07 1999 Organization: Nocturnal Aviation Lines: 73 Mime-Version: 1.0 NNTP-Posting-Host: 1cust94.tnt41.nyc3.da.uu.net Message-ID: <374C6F1F.315988EF@earthlink.net> X-Mailer: Mozilla 4.6 [en] (Win95; U) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Chris Newton wrote: > > David List wrote... > >I see. Thanks, Ahn. Do you know of any other way to output 'true' > >and 'false' instead of '1' and '0'? > > Sorry, I'm not familiar with boolalpha. What exactly are you trying to > achieve here? It's probably fairly simple to do in standard C++ by the > sounds of things, but we need the details. > Look at the following: #include #include // This relies on whether various macros are defined // #define BOOLALPHA // #define IOS_HAS_BOOLALPHA // If your implementation supports a known (non-portable) // constant for boolalpha functionality, change the following // to reflect it and uncomment the line // #define MAGIC_NUMBER 0200000 int main(void) { bool x = false, y = true; cout << "This is a test of boolalpha" #if defined(BOOLALPHA) << endl << "If the manipulator boolalpha works, the" << endl << " line should read \"x = false, y = true\"" << endl << "x = " << boolalpha << x << ", y = " << boolalpha << y #endif << endl; #if defined(IOS_HAS_BOOLALPHA) cout << "Even with a boolalpha manipulator, the following" << endl << "should work using the setiosflags(ios::boolapha) manipulator" << endl << "x = " << setiosflags(ios::boolalpha) << x << ", y = " << y << endl; cout << "Now we reset boolalpha " << resetiosflags(ios::boolalpha) << endl << "x = " << x << ", y = " << y << endl; cout << "Now trying cin.setf(ios::boolalpha)" << endl; cin.setf(ios::boolalpha); cout << "x = " << x << ", y = " << y << endl; #endif #if defined(MAGIC_NUMBER) cout << "A Magic number may solve the implementation's limitations" << endl << "using setiosflags(MAGIC_NUMBER) manipulator" << endl << "x = " << setiosflags(MAGIC_NUMBER) << x << ", y = " << y << endl; cout << "Now we reset boolalpha " << resetiosflags(MAGIC_NUMBER) << endl << "x = " << x << ", y = " << y << endl; cout << "Now trying cin.setf(MAGIC_NUMBER)" << endl; cin.setf(MAGIC_NUMBER); cout << "x = " << x << ", y = " << y << endl; #endif cout << "Finally, a simple solution" << endl; cout << "x = " << (x ? "true" : "false") << ", y = " << (y ? "true" : "false") << endl; } /* vi: set cindent ts=4 sw=4 et tw=72: */ -- Martin Ambuhl (mambuhl AT earthlink DOT net) Note: mambuhl AT tiac DOT net will soon be inactive