0
How do you represent a boolean as a %_
eg for int its %d, String %s
4 Réponses
+ 2
bool is 1 or 0, but maybe you can fake it?
printf("%s", x?"true":"false")
or create a macro:
#define fBool(b)((b)?"true":"false")
x= 3<5;
printf("%s", fBool(x))
+ 1
Bob_Li Thanks for the help👏
+ 1
#include <stdio.h>
#include <stdbool.h>
int main(void) {
    bool x = true;  /* equivalent to bool x = 1; */
    bool y = false; /* equivalent to bool y = 0; */
    if (x)  /* Functionally equivalent to if (x != 0) or if (x != false) */
    {
        puts("This will print!");
    }
    if (!y) /* Functionally equivalent to if (y == 0) or if (y == false) */
    {
        puts("This will also print!");
    }
}
0
/* c++ have std::boolalpha , std::noboolapha*/
#include<iostream>
using namespace std;
int main()
{
    cout<<"when boolalpha flag is off\n";
    cout<<"true: "<<true<<endl;
    cout<<"false: "<<false<<endl;
    cout<<"when boolalpha flag is on\n";
    cout<<boolalpha<<"true: "<<true<<endl;
    cout<<boolalpha<<"false: "<<false<<endl;
    cout<<noboolalpha;
}



