How do I efficiently iterate through a vector and run a method on each object?

My code is setup like this at the moment, I have a vector containing 5 objects of class S and I need to iterate through the vector and run the subPrint() function. What is the most efficient way to do this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int itPos = 0;

vector<S> v;

S s1("Jon");
S s2("Mike");
S s3("Kim");
S s4("Steve");
S s5("Kevin");

v.push_back(s1);
v.push_back(s2);
v.push_back(s3);
v.push_back(s4);
v.push_back(s5);

cout << v[0].subPrint();
A simple loop?
A loop! I never thought about that!
Topic archived. No new replies allowed.