The subscript operator ([]) takes a std::string::size_type value. The operator returns a reference to the character at the given position. The value in the subscript is referred to as "a subscript" pp93 ~ 94 C++ Primer 5ed.
and
A vector is a collection of objects, all of which have the same type. Evey object in the collection has an associated index, which gives access to that object.pp96 C++ Primer 5ed.
Question:
Is string subscript an associated index? If not, what is the difference between the subscript of the std::string type and the associated index of the collection/vector?
Think "index" as "the sequential number of an item," not "index" as "the lookup table in a book."
What they're saying about vectors is that the elements in them can be accessed through sequential numeric indices: v[0]
, v[1]
, etc.
The exact same holds for strings and the characters in them.