Studying C++ I came across with at least three ways of iterating over a standard vector array:
#include <vector>
using namespace std;
int main(){
vector<int> v;
v.resize(10);
for (int&i : v){
i=0;
}
for (int i=0;i<v.size();++i){
v[i]=0;
}
for (vector<int>::iterator i=v.begin();i!=v.end();++i){
*i=0;
}
return 0;
}
- What are the differences ?
- What is the best way according to the task needed ?
Aucun commentaire:
Enregistrer un commentaire