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 after the constructor is called:

• The data() method returns a pointer to the first element of a copy of the array s.

• The size() method returns a value equal to traits::length().

• The capacity() method returns a value at least as large as size().

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.61.218