programming-examples/c++/Others/Assign elements in vector a value through an iterator.cpp
2019-11-15 12:59:38 +01:00

25 lines
428 B
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;
}