devxlogo

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.