在 C++ 中,要比较两个 unsigned short(通常简称为 ushort)类型的数值大小,您可以直接使用标准的比较运算符,如 <、>、== 等
#include<iostream>
int main() {
unsigned short num1 = 42;
unsigned short num2 = 65000;
if (num1 < num2) {
std::cout << "num1 is smaller than num2"<< std::endl;
} else if (num1 > num2) {
std::cout << "num1 is greater than num2"<< std::endl;
} else {
std::cout << "num1 and num2 are equal"<< std::endl;
}
return 0;
}
在这个示例中,我们创建了两个 unsigned short 类型的变量 num1 和 num2,并使用比较运算符判断它们之间的大小。根据比较结果,我们输出相应的信息。