+ 1
using vectors instead of arrays? (C++)
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
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.
- 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 ;