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