Combine insert and end to add elements to the end of vector : vector insert « Vector « C++






Combine insert and end to add elements to the end of vector

   
#include <iostream>
#include <cassert>
#include <algorithm>
#include <string>
#include <list>
#include <deque>
#include <vector>
using namespace std;

int main()
{
  vector<string> vec;


  vec.insert(vec.end(), "AAA");
  vec.insert(vec.end(), "BBBB");
  vec.insert(vec.end(), "CCCCC");


  vector<string>::iterator pos;


  for (pos=vec.begin(); pos!=vec.end(); ++pos) {
        cout << *pos << ' ';
  }

  return 0;
}

/* 
AAA BBBB CCCCC 
 */        
    
    
  








Related examples in the same category

1.Insert element by index
2.Insert element at specific position
3.Insert 10 duplicate value to vector
4.Insert one vector to another vector
5.Insert elements from array
6.Insert characters into vector. An iterator to the inserted object is returned
7.Create and initialize vector with float number array
8.Appending values to Vector Containers after sorting
9.Inserts an element into a vector at given position