float a = 0.0f;
if (a==0.0f)
{
std::cout << "yes" << std::endl;
}
if (a==0)
{
std::cout << "yes" << std::endl;
}
int b = 0;
if (a==b)
{
std::cout << "yes" << std::endl;
}
float c = 0.0f;
if (a==c)
{
std::cout << "yes" << std::endl;
}
输出4个yes
编译器采用:Intel C++ Compiler XE 14.0, vs2010
win7 64位
Corei5 4760K
本文探讨了在C++中使用if语句进行浮点数和整数比较,并通过输出语句展示了比较结果。编译器采用的是IntelC++CompilerXE14.0和vs2010,在Windows764位环境下运行。
1万+

被折叠的 条评论
为什么被折叠?



