Mega Code Archive

 
Categories / C++ Tutorial / Vector
 

Demonstration of size() and capacity()

#include <iostream> #include <vector> int main () {     using namespace std;     // Instantiate a vector object that holds 5 integers of default value     vector <int> v (5);     cout << "Size: " << v.size ();     cout << ", Capacity: " <<  v.capacity () << endl;     // Inserting a 6th element in to the vector     v.push_back (666);     cout << "Size: " << v.size ();     cout << ", Capacity: " <<  v.capacity () << endl;     // Inserting another element     v.push_back (777);     cout << "After inserting yet another element... " << endl;     cout << "Size: " << v.size ();     cout << ", Capacity: " <<  v.capacity () << endl;     return 0; }