This constructor takes an initializer_list<charT>
parameter:
basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
You can use it with a braced list of characters:
string slow({'s', 'n', 'a', 'i', 'l'});
This isn’t the most convenient way to initialize a string
, but it keeps the string
interface similar to that of the STL container classes.
The initializer_list
class has begin()
and end()
members, and the effect of using this constructor is the same using the range constructor:
basic_string(il.begin(), il.end(), a);
3.133.123.34