Constructors That Use C-Style Strings

Constructors that use C-style strings let you initialize a string object from a C-style string; more generally, they let you initialize a charT specialization from an array of charT values:

basic_string(const charT* s, const Allocator& a = Allocator());

To determine how many characters to copy, the constructor applies the traits::length() method to the array pointed to by s. (The pointer s should not be a null pointer.) For example, the following statement initializes the toast object, using the indicated character string:

string toast("Here's looking at you, kid.");

The traits::length() method for type char uses the null character to determine how many characters to copy.

The following relationships hold ...

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.