+ 1

using vectors instead of arrays? (C++)

14th May 2019, 11:40 AM
你知道規則,我也是
你知道規則,我也是 - avatar
3 Respostas
+ 2
Vector are implemented using arrays and will manage resizing automatically when you add/remove values to it. I have to disagree with Théophile on the indexing, arrays have indexing. What they don't have is safe indexing with the at method Example: v.at(4) // will throw an exception if out of range v[4] // could crash your program or return weird values if out of range
14th May 2019, 12:43 PM
Paul
0
My fault, I was comparing lists and arrays... About the indexing, I was speaking about linked lists, which haven't got direct indexing. I'm sorry for that.
14th May 2019, 2:59 PM
Théophile
Théophile - avatar
- 3
Vectors haven't got a fixed size, so that you can add element easily to a vector. And vectors have got indexing : vector[n] = x ;
14th May 2019, 12:05 PM
Théophile
Théophile - avatar