Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sizeof() a vector

Tags:

People also ask

Can you use sizeof on vector?

The sizeof operator returns the size in bytes of the object or expression at compile time, which is constant for a std::vector .

How do you find the size of a 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.

What does sizeof vector return?

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.

What does vector member size () do?

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.