如何遍历C ++字符串向量? [英] How do I Iterate over a vector of C++ strings?

查看:69
本文介绍了如何遍历C ++字符串向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何迭代此C ++向量?

How do I iterate over this C++ vector?

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,那么这也是合法的:

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*
} 

这篇关于如何遍历C ++字符串向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆