C++ 版本的 Python 循环“for i, num in enumerate(list):”

在 python 中,您可以迭代如下列表。在 C++ 中是否有类似的简短方法可以做到这一点?


list = [1,2,3,4,5]

for i, num in enumerate(list):

     # do stuff

类似的东西for(int num : list)很接近,但不一样。


炎炎设计
浏览 205回答 1
1回答

慕运维8079593

C++ 17 次!for(auto [it, i] = tuple{list.begin(), 0}; it != list.end(); it++, i++){&nbsp; &nbsp;cout << *it; //actual item&nbsp; &nbsp;cout << i; //index value}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python