While using the vector why do we sometime use the operator[] like homework[mid] but other times use homework.begin(). Also, homework.end() not homework[end], but that’s like begin. Is it just accessing the elements differently? It’s more confusing this way, don’t you agree?
While using the vector why do we sometime use the operator[] like homework[mid] but
Share
vector::operator[] retrieves the Nth element of the vector. Such an operator is defined only for select STL container classes.
vector.end() is a method returning an iterator. Iterators are special entities for working with STL containers, vector included. vector::end() points onto the element immediately following the last element of the vector – it’s often treated as a value to campare the iterator against to determine whether the whole container has been traversed.