Mail Archives: djgpp/1999/05/26/18:40:35
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 <iostream>
#include <iomanip>
// 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
- Raw text -