C++ Language/Std/Stl/CollectionClasses/SequenceCollections/Vector/Indexing

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Both the C-array-operator (veciVar[3]) and veciVar.at(3) allow random access to a vector's items. They differ in how they handle the error of a non-existent item. Because either of them provides a reference to that item, indexing can be used for getting it and for setting it.

A reference is also returned by the special names for the first and last items veciVar.front() and veciVar.back().

Additional information about vector indexing (includes interactive examples)