vector with pinter cout c++
First, let's create a vector of integers using the C++ standard library.
#include <iostream>
#include <vector>
int main() {
std::vector<int> numbers = {1, 2, 3, 4, 5};
Next, let's declare an iterator and use it to iterate through the vector.
std::vector<int>::iterator it;
for (it = numbers.begin(); it != numbers.end(); ++it) {
Within the loop, we'll use the dereferencing operator to access the value pointed to by the iterator and then use cout to display it.
std::cout << *it << " ";
}
Finally, we'll end the loop and the main function.
return 0;
}