#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vectorObject;
int i;
for(i = 0; i <10; i++)
vectorObject.push_back(i);
cout << "Initial contents of vectorObject: ";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[i] << " ";
cout << endl;
cout << "Initial size of vectorObject: ";
cout << vectorObject.size() << endl;
cout << "Initial capacity of vectorObject: ";
cout << vectorObject.capacity() << "\n\n";
vectorObject.clear();
cout << "Size of vectorObject after clear(): ";
cout << vectorObject.size() << endl;
cout << "Capacity of vectorObject after clear(): ";
cout << vectorObject.capacity() << "\n\n";
// put new values in vectorObject
for(i = 0; i <10; i++)
vectorObject.push_back(i*10);
cout << "New contents of vectorObject: ";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[i] << " ";
cout << endl;
cout << "Size of vectorObject after adding new elements: ";
cout << vectorObject.size() << endl;
cout << "Capacity of vectorObject after adding new elements: ";
cout << vectorObject.capacity() << "\n\n";
return 0;
}
|