Default Constructor

This is the prototype for the default constructor:

explicit basic_string(const Allocator& a = Allocator());

Typically, you would accept the default argument for the allocator class and would use the constructor to create empty strings:

string bean;wstring theory;

The following relationships hold after the default constructor is called:

• The data() method returns a non-null pointer to which 0 can be added.

• The size() method returns 0.

• The return value for capacity() is not specified.

Suppose you assign the value returned by data() to the pointer str. In this case, the first condition means str + 0 is valid.

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.