将输入的整数直接赋值给 bool 变量。整数为 0 时结果为 false,否则为 true。使用 boolalpha 输出英文布尔值。
bool
0
false
true
boolalpha
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; bool result = n; cout << boolalpha << result << endl; return 0; }
使用您的 椰子OJ CoconutOJ 通用账户