Constructor That Uses a Range

A constructor that uses a range uses an iterator-defined range in the style of the STL:

template<class InputIterator>basic_string(InputIterator begin, InputIterator end,                const Allocator& a = Allocator());

The begin iterator points to the element in the source at which copying begins, and end points to one past the last location to be copied.

You can use this form with arrays, strings, or STL containers:

char cole[40] = "Old King Cole was a merry old soul.";string title(cole + 4, cole + 8);vector<char> input;char ch;while (cin.get(ch) && ch != '\n')    input.push_back(ch);string str_input(input.begin(), input.end());

In the first use, InputIterator is evaluated to type const char *. In the second use, ...

Get C++ Primer Plus 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.