Output the manipulator 'boolapha' to the 'cout' stream
before outputting your booleans. Also make sure you
#include <iomanip>.
Actually, there is no need to #include <iomanip>, as std::boolalpha is
declared in header <ios>, which must be included by <ostream(if my
understanding is correct).
>
Yup. That's one of those places where operator abuse can stab you in the
back.
>
PS: Yes, using bit shift operators for stream I/O counts as operator abuse
in my eyes.
Heh...
Is it still abuse if you call them insertion/extraction operators?
What else would one use?
Before someone provides a cheaper answer, may I ask if one might imbue a
locale?
>
(Note that some cultures don't call a positive boolean "true" ;-)
I'm just curious, have you seen an implementation where the output would not
be "true" and "false" for some locale? I have tried it here, because I
somehow expected "vrai"/"faux", "juist"/"fout", "wahr"/"falsch" and alike.
(I was disappointed, it was always "true"/"false")
> Output the manipulator 'boolapha' to the 'cout' stream
>>before outputting your booleans. Also make sure you
>>#include <iomanip>.
>
>
Actually, there is no need to #include <iomanip>, as std::boolalpha is
declared in header <ios>, which must be included by <ostream(if my
understanding is correct).
I'm just curious, have you seen an implementation where the output would
not
be "true" and "false" for some locale? I have tried it here, because I
somehow expected "vrai"/"faux", "juist"/"fout", "wahr"/"falsch" and alike.
(I was disappointed, it was always "true"/"false")
Post your code. Maybe "true" and "false" are considered data, not human
interface, so the locales don't affect them.
I never studied this topic; I just wanted to learn more about locales.
>>
>Yup. That's one of those places where operator abuse can stab you in the
>back.
>>
>PS: Yes, using bit shift operators for stream I/O counts as operator abuse
>in my eyes.
>
>Heh...
>
>Is it still abuse if you call them insertion/extraction operators?
>What else would one use?
+= or no operator at all (just print())? I agree with Rolf Magnus on
operator overloading abuse in iostreams.
Victor Bazarov wrote:
>
std::cout << (a ? "true" : "false");
>
Yup. That's one of those places where operator abuse can stab you in the
back.
>
PS: Yes, using bit shift operators for stream I/O counts as operator abuse
in my eyes.
Heh...
Is it still abuse if you call them insertion/extraction operators?
What else would one use?
>
+= or no operator at all (just print())? I agree with Rolf Magnus on
operator overloading abuse in iostreams.
>
// test1.cpp
#include <iostream>
int main() {
int a = 1;
std::cout += a;
return 0;
}
g++ test1.cpp
test1.cpp: In function `int main()':
test1.cpp:5: error: no match for 'operator+=' in 'std::cout += a'
Comment