Lines 8–9 declare
string string1 and
string::const_iterator iterator1. Recall that a
const_iterator cannot be used to modify the data that you’re iterating through— in this case the
iterator1 is initialized to the beginning of
string1 with the
string class member function
begin. Two versions of
begin exist—one that returns an
iterator for iterating through a non-
const string and a
const version that returns a
const_iterator for iterating through a
const string. Line 11 outputs
Lines 15–18 use iterator
iterator1 to “walk through”
string member function
end returns an
iterator (or a
const_iterator) for the ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.