Edit

Share via


<string_view>

Defines the class template basic_string_view and related types and operators. (Requires compiler option std:c++17 or later.)

Syntax

#include <string_view>

Remarks

The string_view family of template specializations provides an efficient way to pass a read-only, exception-safe, non-owning handle to the character data of any string-like objects with the first element of the sequence at position zero. A function parameter of type string_view (which is a typedef for basic_string_view<char>) can accept arguments such as std::string, char*, or any other string-like class of narrow characters for which an implicit conversion to string_view is defined. Similarly, a parameter of wstring_view, u16string_view or u32string_view can accept any string type for which an implicit conversion is defined. For more information, see basic_string_view Class.

Typedefs

Type name Description
string_view A specialization of the class template basic_string_view with elements of type char.
wstring_view A specialization of the class template basic_string_view with elements of type wchar_t.
u16string_view A specialization of the class template basic_string_view with elements of type char16_t.
u32string_view A specialization of the class template basic_string_view with elements of type char32_t.

Operators

The <string_view> operators can compare string_view objects to objects of any convertible string types.

Operator Description
operator!= Tests if the object on the left side of the operator isn't equal to the object on the right side.
operator== Tests if the object on the left side of the operator is equal to the object on the right side.
operator< Tests if the object on the left side of the operator is less than to the object on the right side.
operator<= Tests if the object on the left side of the operator is less than or equal to the object on the right side.
operator<\< A template function that inserts a string_view into an output stream.
operator> Tests if the object on the left side of the operator is greater than to the object on the right side.
operator>= Tests if the object on the left side of the operator is greater than or equal to the object on the right side.

Literals

Operator Description
sv Constructs a string_view, wstring_view, u16string_view, or u32string_view depending on the type of the string literal to which it's appended.

Classes

Class Description
basic_string_view Class A class template that provides a read-only view into a sequence of arbitrary character-like objects.
hash Function object that produces a hash value for a string_view.

Requirements

  • Header: <string_view>

  • Namespace: std

  • Compiler Option: std:c++17 or later.

See also

Header Files Reference