for循环
C中for
string str = “hello world”;
for(int i = 0; i < str.length();i++)
{
cout << str[i] <<endl;
}
利用迭代器的for循环
for(string::iterator it=str.begin();it!=str.end();it++)
{
cout<<*it;
}
利用auto
关键字简化迭代器版本的for循环
for (auto it=str.begin();it!=str.end;it++)
{
cout << *it;
}
C++11 新for
循环称为,基于范围的for循环
for(auto s:str)
{
cout << s;
}