C++ for循环遍历几种写法

最近写for循环,发现以前用过的方法都忘记了,这里整理下几种方法,欢迎大佬补充:

1、

for(itnt n =1;n<5;n++)

{

}

2、

for (auto it = list.begin(); it != list.end(); ++it)  
{  

}

3、

for each(auto item in list)  
{  
//item是list每个元素的值
}   

4、

for (auto item : list)

{

//item是list每个元素的值

}

5、

std::for_each(list.begin(), list.end(), [](string item)
{
string A = item;
});

原文地址:https://www.cnblogs.com/132818Creator/p/11208541.html