使用新版本的C++关键字for的新语法。
同时也有新版本的C++关键字auto,自动类型推断,可以推断返回类型,用于声明新的变量。
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::endl;
using std::vector;
int main()
{
vector <string> coll;
coll.push_back("fsd");
coll.push_back("fsd");
coll.push_back("fsd");
coll.push_back("fsd");
coll.push_back("fsd");
/*新建里一个容器的元素类型一样的参数 ptr
如果不清楚是什么类型
可以使用auto,使用类型推断来建立ptr的类型*/
for(string ptr : coll)//使用C++11 新增加的关键字for的新版本
{
cout<<ptr<<endl;
}
return 0;
}