我经常听到,在编译C和C ++程序时,我应该“始终启用编译器警告”。为什么这是必要的?我怎么做?
有时我也听说我应该“将警告视为错误”。我是不是该?我怎么做?
概括一下,为什么不2 < x < 9等于2 < x && x < 9?
这是我编写的测试代码:
#include <iostream>
int main()
{
int nums[] = { 5 , 1, 10};
// We are gonna check if the number is in the range 2 - 9
for (auto e : nums)
{
if (2 < e < 9)
std::cout << "2 < " << e << " < 9" << std::endl;
if(2 < e && e < 9)
std::cout << "2 < …Run Code Online (Sandbox Code Playgroud) 有人可以告诉我为什么以下不起作用?(我的意思是没有输出)
if(0.0001<0.001<0.01)
cout<<"hi\n"<<endl;
output: (blank)
Run Code Online (Sandbox Code Playgroud)
虽然以下工作:
if(0.0001<0.001 && 0.001<0.01)
cout<<"hi\n"<<endl;
output:hi
Run Code Online (Sandbox Code Playgroud)