1.迭代器
2.C++11 新增关键字auto
3.数组遍历法
4.基于范围的for循环
#include
#include
using namespace std;
int main()
{
vector<int>obj;
for(int i=0;i<10;i++)
{
obj.push_back(i);
cout<<obj[i]<<",";
}
cout << endl << "vector size is :" << obj.size() << endl;
//iterator遍历
for(vector<int>::iterator it = obj.begin(); it != obj.end(); it++)
{
cout << *it << ",";
}
cout << endl;
//数组循环遍历
for(int i=0;i<obj.size();i++)
{
cout<<obj[i]<<",";
}
cout << endl;
//auto关键字遍历遍历
for(auto it = obj.begin(); it != obj.end(); it++)
{
cout << *it << ",";
}
cout << endl;
//基于范围的for循环
for (auto iter : obj)
{
cout << iter << ",";
}
cout << endl;
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)