+ 2

C++ STL

In a vector<int> v; what is the difference between 1 and 2? void f(vector<int>& v) { v[0]; // 1. v.at(0); // 2. }

1st Apr 2017, 10:28 AM
Dimas Fajar
Dimas Fajar - avatar
2 ответов
+ 3
its better to use 2nd because you can change your data structure easily in future just by changing vector to list (for example) in definition line ; but in first one you have to replace v[] with v.at() in order to use map or list or ...
1st Apr 2017, 11:51 AM
Amir Hossein Farzin
Amir Hossein Farzin - avatar
+ 1
thx 4 d answer amir
1st Apr 2017, 1:20 PM
Dimas Fajar
Dimas Fajar - avatar