下面的代码
#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
}
为什么第二个输出不是-1?第二场会发生什么?
最佳答案
vector::size()
是size_t
类型,是无符号类型,无符号整数不能表示负数。
关于c++ - vector 大小 - 在 C++ 中大小为 0 时为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34701662/