向量大小 - 在C++中大小为0时为1

Zig*_*bra 2 c++ size vector

以下代码

#include <vector>
#include <iostream>
using namespace std;
int main() {
    vector<int> value;
    cout << value.size() << endl;  // output 0
    cout << value.size() - 1 << endl;  // output 18446744073709551615
}
Run Code Online (Sandbox Code Playgroud)

为什么第二个输出不是-1?第二次cout会发生什么?

Jon*_*ter 6

vector::size()size_t无符号类型的类型,无符号整数不能表示负数.