vector取size问题
Contents
缘起
最近迷上了sizeof
,感觉比sizeof()
炫酷多了
|
|
冲突
然后我就习惯性地使用着sizeof
,直到我写了如下代码
|
|
分析
原因分析:
sizeof是对精确的数据类型操作
sizeof(type) sizeof expression
- Yields the size in bytes of the object representation of type.
- Yields the size in bytes of the object representation of the type of expression, if that expression is evaluated.
而vector是一个类
A std::vector is a class. It’s not the actual data, but a class that manages it. Use std::vector.size() to get the size of the actual data.
所以应该是
|
|