这是我的测试代码
#include<iostream>
using namespace std;
int main()
{
uint8_t a;
while(1)
{
cin>>a;
if(a == 0) break;
cout<<"Input is "<<a<<endl;
}
}
Run Code Online (Sandbox Code Playgroud)
当我执行(使用我的输入)时,这就是我得到的
1
Input is 1
2
Input is 2
12
Input is 1
Input is 2
0
Input is 0
3
Input is 3
Run Code Online (Sandbox Code Playgroud)
问题1:它将输入12作为两个独立的输入
问题2:条件是否= = 0不起作用
可能是什么问题?
uint8_t是一个typedef用于一个unsigned char.这意味着将读取一个字符cin.
当"0"读取时,它实际上是字符的ascii值'0'48,这不是零,因此等式检查失败.