AIM: 
To implement a C++ program to illustrate the concept of standard template library.
To implement a C++ program to illustrate the concept of standard template library.
ALGORITHM:
Step 1: Include the header files
Step 2: Create a vector to store int
Step 3: Display the original size to store int
Step 4: Push 5 values into the vector using for loop
Step 5: Display extended size of vec
Step 6: Access 5 values from the vector
Step 7: Use iterator to access the values 
PROGRAM:
#include <iostream.h>
#include <vector>
using namespace std;
 int main()
{
   vector<int> vec; 
   int i;
   cout << "vector size = " << vec.size() << endl;
   for(i = 0; i < 5; i++)
{
      vec.push_back(i);
}
   cout << "extended vector size = " << vec.size() << endl;
      for(i = 0; i < 5; i++)
{
      cout << "value of vec [" << i << "] = " << vec[i] << endl;
   }
   vector<int>::iterator v = vec.begin();
   while( v != vec.end()) {
      cout << "value of v = " << *v << endl;
      v++;
   }
   return 0;
}
SAMPLE OUTPUT:
vector size = 0
extended vector size = 5
value of vec [0] = 0
value of vec [1] = 1
value of vec [2] = 2
value of vec [3] = 3
value of vec [4] = 4
value of v = 0
value of v = 1
value of v = 2
value of v = 3
value of v = 4
RESULT:
                 Thus a C++ program to illustrate the concept of standard template library is implemented successfully.
 
   
No comments:
Post a Comment