如何迭代这个 C++ 向量?
vector<string> features = {"X1", "X2", "X3", "X4"};
尝试这个:
for(vector<string>::const_iterator i = features.begin(); i != features.end(); ++i) {
// process i
cout << *i << " "; // this will print all the contents of *features*
}
如果您使用 C++11,那么这也是合法的:
for(auto i : features) {
// process i
cout << i << " "; // this will print all the contents of *features*
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)