forint friendIndexfriendsi可以用什么代替c++
可以使用以下两种方式代替:
- 使用传统的for循环:
for(int j=0; j<friends[i].size(); j++) {
int friendIndex = friends[i][j];
// 其他操作
}
- 使用范围-based for循环(C++11引入的新特性):
for(auto friendIndex : friends[i]) {
// 其他操作
}
这两种方式都可以达到与原代码相同的效果,只是写法略有不同。
原文地址: https://www.cveoy.top/t/topic/hKCC 著作权归作者所有。请勿转载和采集!