The sizeof operator returns the size in bytes of the object or expression at compile time, which is constant for a std::vector .
To get the size of a C++ Vector, you can use size() function on the vector. size() function returns the number of elements in the vector.
Returns the number of elements in the vector. This is the number of actual objects held in the vector, which is not necessarily equal to its storage capacity.
size() – Returns the number of elements in the vector. max_size() – Returns the maximum number of elements that the vector can hold. capacity() – Returns the size of the storage space currently allocated to the vector expressed as number of elements.
I have a vector<set<char> >
data structure (transactions database) and I want to know the size of it. When I use sizeof() with each set<char>
the size is 24 in spite of the set contains 3, 4 or 5 chars. Later, when I use sizeof() with the vector<set<char> >
the size is 12... I suppose this is not the way to know the size of a data structure. Any help?
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With