Examining how Many Elements a Container is Currently Holding

You can detect how many elements are currently stored in a container by calling the member function size():

 vector  vi; //create a vector of int'sfor (int i = o; i < 10; i++) //fill vector{  vi.push_back(i);}cout<< "vi currently holds"<< vi.size() <<" elements" << endl;

All STL containers provide this member function. Please note that size() returns the number of elements stored in the container, not the number of bytes.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: