How do I Iterate over a vector of C++ strings?

c++, loops, vector

Solution

Try this:

for(vector<string>::const_iterator i = features.begin(); i != features.end(); ++i) {
    // process i
    cout << *i << " "; // this will print all the contents of *features*
}

If you are using C++11, then this is legal too:

for(auto i : features) {
    // process i
    cout << i << " "; // this will print all the contents of *features*
} 

Problem

How do I iterate over this C++ vector? `vector<string> features = {"X1", "X2", "X3", "X4"};`

Original source

Related problems