Note, this article is not finished! You can help by editing this doc page.
String view class reference
Overview
- Simplified
- Detailed
template< class CharT, /* ... */ >
class basic_string;
template<
class CharT,
class Traits = std::char_traits<CharT>,
class Allocator = std::allocator<CharT>
>
class basic_string;
A class that is used as a lightweight view over a sequence of characters.
Memory
This section requires improvement. You can help by editing this doc page.
Aliases
Type std::string_view
is in fact an alias to: std::basic_string_view<char>
.
Available std::basic_string_view
aliases
pub | std::string_view | std::basic_string_view<char> |
pub | std::wstring_view | std::basic_string_view<wchar_t> |
pub | std::u8string_view (od C++20) | std::basic_string_view<char8_t> |
pub | std::u16string_view (od C++11) | std::basic_string_view<char16_t> |
pub | std::u32string_view (od C++11) | std::basic_string_view<char32_t> |
Technical details
Technical definition of a string view
The class template basic_string_view
describes an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero.
A typical implementation holds only two members: a pointer to constant CharT
and a size.
std::basic_string_view
is a TriviallyCopyable
type. (od C++11)Named requirements
std::basic_string_view
meets the requirements of:
-
TriviallyCopyable (od C++23)
-
zanotuj
Specializations of
std::basic_string_view
are already trivially copyable types in all existing implementations, even before the formal requirement introduced in C++23.
-
Feature testing macros
This section requires improvement. You can help by editing this doc page.
std::string_view
Defined in | string_view |
Template parameters
pub | CharT | Character type |
pub | Traits |
important Like for |
Type names
pub | traits_type | Traits |
pub | value_type | CharT |
pub | pointer | CharT* |
pub | const_pointer | const CharT* |
pub | reference | CharT |
pub | const_reference | const CharT& |
pub | const_iterator | implementation-defined constant |
pub | const_reverse_iterator | std::reverse_iterator<const_iterator> |
pub | reverse_iterator | const_reverse_iterator |
pub | size_type | std::size_t |
pub | difference_type | std::ptrdiff_t |
iterator
and const_iterator
are the same type because string views are views into constant character sequences.
All requirements on the iterator types of a Container
applies to the iterator
and const_iterator
types of std::basic_string_view
as well.
Member functions
pub | (constructors) | Constructs a string view. |
pub | (destructor) | Destroys the string view. |
pub | operator= | Assigns values to the string string view. |
Element access
pub | at | Accesses the specified character with bounds checking. |
pub | operator[] | Accesses the specified character. |
pub | front | Returns the first character. |
pub | back | Returns the last character. |
pub | data | Returns a pointer to the first character of a view. |
Iterators
pub | begin cbegin | Returns an |
pub | end cend | Returns an |
pub | rbegin crbegin | Returns a reverse |
pub | rend crend | Returns a reverse |
Capacity
pub | empty | Returns |
pub | size length | Returns the number of characters. |
pub | max_size | Returns the maximum number of characters. |
Modifiers
pub | remove_prefix | Shrinks the view by moving its start forward. |
pub | remove_suffix | Shrinks the view by moving its end backward. |
pub | swap | Swaps the contents. |
Operations
pub | copy | Copies characters. |
pub | substr | Returns a substring. |
pub | compare | Compares two views. |
pub | starts_with (od C++20) | Checks if the view starts with the given prefix. |
pub | ends_with (od C++20) | Checks if the view ends with the given suffix. |
pub | contains (od C++23) | Checks if the view contains the given substring or character. |
pub | find | Find the first occurrence of a substring. |
pub | rfind | Find the last occurrence of a substring. |
pub | find_first_of | Find first occurrence of characters. |
pub | find_first_not_of | Find first absence of characters. |
pub | find_last_of | Find last occurrence of characters. |
pub | find_last_not_of | Find last absence of characters. |
Constants
pubstaticconstexpr | npos | A special value. The exact meaning depends on the context. |