【发布时间】:2023-04-11 04:13:02
【问题描述】:
我正在编写一个用于在十进制和二进制基数系统之间进行转换的函数,这是我的原始代码:
void binary(int number)
{
vector<int> binary;
while (number == true)
{
binary.insert(binary.begin(), (number % 2) ? 1 : 0);
number /= 2;
}
for (int access = 0; access < binary.size(); access++)
cout << binary[access];
}
在我这样做之前它没有工作:
while(number)
怎么了
while(number == true)
这两种形式有什么区别? 提前致谢。
【问题讨论】:
标签: c++ while-loop evaluation conditional-statements boolean-expression