当前位置:网站首页>52. [Bool type input any non-0 value is not 1 version reason]
52. [Bool type input any non-0 value is not 1 version reason]
2022-08-02 08:21:00 【Lee is struggling...】
[visual studio 2022 version]
[that is, the bool type is not assigned an initial value]
#include
using namespace std;
int main()
{
bool x;
cout << "Please enter the bool value manually:" << endl;
cin >> x;
cout << "The result is:" << x << endl;
return 0;
}
==========================
[The initial value of bool is assigned]
#include
using namespace std;
int main()
{
bool x=false;
cout << "Please enter the bool value manually:" << endl;
cin >> x;
cout << "The result is:" < return 0; } #include using namespace std; int main() { bool x; cout << "Please enter the bool value manually:" << endl; cin >> x; cout << "The result is:" << x << endl; return 0; } ======================== #include using namespace std; int main() { bool x=false; cout << "Please enter the bool value manually:" << endl; cin >> x; cout << "The result is:" < return 0; } ======================== #include } =================================
[visual studio 2015 version]
[That is, the bool type is not assigned an initial value]
[When bool is assigned an initial value (will become false)]
Why is this happening?
Because when the bool type variable is assigned through cin, if the input is "non-0, non-1", the variable value does not change.That is, the bool type variable can only be assigned 0 or 1 through cin, and the others are invalid.
How to change it?
Generally, it is judged by setting the intermediate quantity, and then indirectly assigning the bool variable.Regardless of whether x is defined or not, the bool type variable x is forcibly assigned through the int type variable a, which effectively solves the above problems.
[Forced assignment]
using namespace std;
int main()
{
bool x=false;
cout << "Please enter the bool value manually:" << endl;
int a;
cin >> a;
x = a;
cout << "The result is:" <
边栏推荐
- Appium swipe problem
- DeadLock的可视化分析
- Comprehensive experiment of MPLS and BGP
- 2022-7-31 12点 程序爱生活 恒指底背离中,有1-2周反弹希望
- Database Plus 的云上之旅:SphereEx 正式开源 ShardingSphere on Cloud 解决方案
- Thesis understanding: "Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution, Denoising, and "
- IO进程线程->进程->day4
- 通过建立新的SaaS业务来推动增长的六种方法
- 3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
- mysql启动报错The server quit without updating PID file几种解决办法
猜你喜欢
多版本node的安装与切换详细操作
Inverter insulation detection detection function and software implementation
flutter 自己写一个组件
HCIP 第十三天
解决IDEA安装安装插件慢问题
2022-08-01 第四小组 修身课 学习笔记(every day)
prometheus监控mysql_galera集群
Thesis understanding: "Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution, Denoising, and "
论文理解:“Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution,Denoising, and “
停止精神内耗 每日分享
随机推荐
BGP通过MPLS解决路由黑洞
@RequestParam使用
牛客2022 暑期多校4 D Jobs (Easy Version)(递推优化策略)
redis-advanced
读入、输出优化
Debian 10 dhcp relay (dhcp 中继) dhcp 固定分配
UG NX二次开发(C#)-外部模式-导出dwg格式的文件
HCIP 第十天
传递泛型给JSX元素
Biotinyl Cystamine|CAS:128915-82-2|生物素半胱胺
18、优化网站性能
典型的一次IO的两个阶段是什么?阻塞、非阻塞、同步、异步
2022-7-31 12点 程序爱生活 恒指底背离中,有1-2周反弹希望
MySQL事务(transaction) (有这篇就足够了..)
MySQL - locking mechanism
Xilinx Constraint Study Notes - Timing Constraints
flutter解决键盘和输入框不适配问题
metabase访问adb mysql 如何控制会话时区??
node(三) 模块化
.NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0