Assign elements in vector a value through an iterator : vector begin end « Vector « C++






Assign elements in vector a value through an iterator


#include <iostream>
#include <vector>
#include <cctype>
using namespace std;

int main()
{
  vector<char> v(10); // create a vector of length 10
  vector<char>::iterator p; // create an iterator
  int i;

  // assign elements in vector a value
  p = v.begin();
  i = 0;
  while(p != v.end()) {
    *p = i + 'a';
    p++;
    i++;
  }


  return 0;
}


    
  








Related examples in the same category

1.Vector Basic: begin(), pop_back(), push_back()