跳转到内容

C++也有and, or, not

就像 python 一样。

在 Professional C++ 第 15 章有介绍,Alternative Notation.

#include <format>
#include <iostream>
int main()
{
int i{0};
if (i < 5 or i > -1) {
std::cout << std::format("hello {}", i) << std::endl;
}
if (i < 5 and i > -1) {
std::cout << std::format("world {}", i) << std::endl;
}
if (not i) {
std::cout << std::format("ha {}", i) << std::endl;
}
return 0;
}