可以使用以下两种方式代替:

  1. 使用传统的for循环:
for(int j=0; j<friends[i].size(); j++) {
   int friendIndex = friends[i][j];
   // 其他操作
}
  1. 使用范围-based for循环(C++11引入的新特性):
for(auto friendIndex : friends[i]) {
   // 其他操作
}

这两种方式都可以达到与原代码相同的效果,只是写法略有不同。

forint friendIndexfriendsi可以用什么代替c++

原文地址: https://www.cveoy.top/t/topic/hKCC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录