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;
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM