更新时间:2023-11-09 23:34:46
您想要 vector :: size()
和 set :: size()
。
假设 v
是您的向量,请执行以下操作:
Assuming v
is your vector, do this:
size_t size = 0;
for (vector<set<char> >::const_iterator cit = v.begin(); cit != v.end(); ++cit) {
size += cit->size();
}
sizeof()
是给你应用的对象/类型的内存大小,以 sizeof(char)
(通常为一个字节)的倍数。如果你想知道容器及其元素的内存大小,你可以这样做:
sizeof()
is giving you the in-memory size of the object/type it is applied to, in multiples of sizeof(char)
(usually one byte). If you want to know the in-memory size of the container and its elements, you could do this:
sizeof(v)+ sizeof T)* v.capacity(); //其中T是元素类型