相关疑难解决方法(0)

C ++向量大小。为什么-1大于零

请看一下这个简单的程序:

#include <iostream>
#include <vector>

using namespace std;

int main() {

vector<int> a;

std::cout << "vector size " << a.size() << std::endl;

int b = -1;

if (b < a.size())
   std::cout << "Less";
else
   std::cout << "Greater";

    return 0;
Run Code Online (Sandbox Code Playgroud)

}

尽管很明显-1小于0,但它仍输出“ Greater”,这让我感到困惑size。谁能解释一下?

c++ comparison unsigned vector

2
推荐指数
1
解决办法
2289
查看次数

标签 统计

c++ ×1

comparison ×1

unsigned ×1

vector ×1