string

## `string`

The native type of string values.

### Synopsis

Defined in header <boost/json/string.hpp>.

    class string;

### Types

Name | Description
--- | ---
`allocator_type` | Associated Allocator
`const_iterator` | A random access const iterator to an element.
`const_pointer` | A const pointer to an element.
`const_reference` | A const reference to an element.
`const_reverse_iterator` | A reverse random access const iterator to an element.
`difference_type` | The type used to represent signed integers.
`iterator` | A random access iterator to an element.
`pointer` | A pointer to an element.
`reference` | A reference to an element.
`reverse_iterator` | A reverse random access iterator to an element.
`size_type` | The type used to represent unsigned integers.
`value_type` | The type of a character.

### Member Functions

Name | Description
--- | ---
`append` | Append characters to the string.
`assign` | Assign characters to a string.
`at` | Return a character with bounds checking.
`back` | Return the last character.
`begin` | Return an iterator to the beginning.
`c_str` | @}
`capacity` | Return the number of characters that can be held in currently allocated memory.
`cbegin` | Return a const iterator to the first element.
`cend` | Return a const iterator past the last element.
`clear` | Clear the contents.
`compare` | Compare a string with the string.
`copy` | Copy a substring to another string.
`crbegin` | Return a const reverse iterator to the first element of the reversed container.
`crend` | Return a const reverse iterator to the character following the last character of the reversed container.
`data` | Return the underlying character array directly.
`empty` | Check if the string has no characters.
`end` | Return an iterator to the end.
`ends_with` | Check if the string ends with given suffix.
`erase` | Remove characters from the string.
`find` | Find the first occurrence of characters within the string.
`find_first_not_of` | Find the first character missing from the specified string.
`find_first_of` | Find the first character present in the specified string.
`find_last_not_of` | Find the last character missing from the specified string.
`find_last_of` | Find the last character present in the specified string.
`front` | Return the first character.
`get_allocator` | Return the associated allocator.
`grow` | Increase size without changing capacity.
`insert` | Insert characters at the specified index.
`operator std::string_view` | Convert to `std::string_view` referring to the string.
`operator string_view` | Convert to a `string_view` referring to the string.
`operator+=` | Append characters to the string.
`operator=` | Assignment operators.
`operator[]` | Return a character without bounds checking.
`pop_back` | Remove the last character.
`push_back` | Append a character.
`rbegin` | Return a reverse iterator to the first character of the reversed container.
`rend` | Return a reverse iterator to the character following the last character of the reversed container.
`replace` | Replace a substring with another string.
`reserve` | Increase the capacity to at least a certain amount.
`resize` | Change the size of the string.
`rfind` | Find the last occurrence of a string within the string.
`shrink_to_fit` | Request the removal of unused capacity.
`size` | Return the number of characters in the string.
`starts_with` | Return whether the string begins with another string.
`storage` | Return the associated memory resource.
`string` [constructor] | Constructors.
`subview` | Return a view.
`swap` | Swap the contents.
`try_at` | Return a character with bounds checking.
`~string` [destructor] | Destructor.

### Static Member Functions

Name | Description
--- | ---
`max_size` | Return the maximum number of characters any string can hold.

### Static Data Members

Name | Description
--- | ---
`npos` | A special index.

### Friends

Name | Description
--- | ---
`operator<<` | Serialize a `string` to an output stream.
`swap` | Exchange the given values.

### Description

Instances of string store and manipulate sequences of `char` using the UTF-8 encoding. The elements of a string are stored contiguously. A pointer to any character in a string may be passed to functions that expect a pointer to the first element of a null-terminated `char` array. The type uses small buffer optimisation to avoid allocations for small strings.

String iterators are regular `char` pointers.

| `string` member functions do not validate any UTF-8 byte sequences passed to them.

### Thread Safety

Non-const member functions may not be called concurrently with any other member functions.

### Satisfies

ContiguousContainer, ReversibleContainer, and SequenceContainer.

Convenience header <boost/json.hpp>.

Edit this page