Ron*_*nis 34
试试这个:
for(vector<string>::const_iterator i = features.begin(); i != features.end(); ++i) {
// process i
cout << *i << " "; // this will print all the contents of *features*
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是C++ 11,那么这也是合法的:
for(auto i : features) {
// process i
cout << i << " "; // this will print all the contents of *features*
}
Run Code Online (Sandbox Code Playgroud)
Kon*_*lph 11
如果编译,您使用的C++ 11允许以下内容:
for (string& feature : features) {
// do something with `feature`
}
Run Code Online (Sandbox Code Playgroud)
如果您不想改变该功能,您也可以将其声明为string const&(或只是string,但这将导致不必要的副本).
| 归档时间: |
|
| 查看次数: |
53275 次 |
| 最近记录: |