//遍历容器元素
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class A
{
public:
int id=0;
};
int main()
{
vector<A> v;
A a0,a1,a2;
a0.id=1;a1.id=2;a2.id=3;
v.push_back(a0);v.push_back(a1);v.push_back(a2);
// for (std::vector<A>::iterator item = v.begin(); item != v.end(); ++item)//注释的四行也是可以的
// {
// cout<<item->id<<endl;
// }
for (auto & item:v) //c++11语法
{
cout<<item.id<<endl;
}
string s="Jack-Ma";
for (auto & item:s)
{
cout<<item<<endl;
}
system("pause");
return 0;
}