The basic operation of a vector: size, push_back,
#include <iostream>
#include <vector>
#include <cctype>
using namespace std;
int main()
{
vector<char> vectorObject(10); // create a vector of length 10
unsigned int i;
cout << "Size = " << vectorObject.size() << endl;
for(i=0; i<10; i++)
vectorObject[i] = i + 'a';
cout << "Current Contents:\n";
for(i=0; i<vectorObject.size(); i++)
cout << vectorObject[i] << " ";
cout << "\n\n";
cout << "Expanding vector\n";
for(i=0; i<10; i++)
vectorObject.push_back(i + 10 + 'a');
cout << "Size now = " << vectorObject.size() << endl;
cout << "Current contents:\n";
for(i=0; i<vectorObject.size(); i++)
cout << vectorObject[i] << " ";
cout << "\n\n";
for(i=0; i<vectorObject.size(); i++)
vectorObject[i] = toupper(vectorObject[i]);
cout << "Modified Contents:\n";
for(i=0; i<vectorObject.size(); i++)
cout << vectorObject[i] << " ";
cout << endl;
return 0;
}
Related examples in the same category