Use for_each() in vector
#include <iostream> #include <vector> #include <algorithm> using namespace std; void show(int i) { cout << i << " "; } int main() { vector<int> vectorObject; int i; for(i = 0; i <10; i++) vectorObject.push_back(i); cout << "Contents of vectorObject: "; for_each(vectorObject.begin(), vectorObject.end(), show); cout << endl; return 0; }