Defined in header <string_view> | ||
---|---|---|
constexpr string_view operator "" sv(const char* str, size_t len) noexcept; | (1) | (since C++17) |
constexpr u8string_view operator "" sv(const char8_t* str, size_t len) noexcept; | (2) | (since C++20) |
constexpr u16string_view operator "" sv(const char16_t* str, size_t len) noexcept; | (3) | (since C++17) |
constexpr u32string_view operator "" sv(const char32_t* str, size_t len) noexcept; | (4) | (since C++17) |
constexpr wstring_view operator "" sv(const wchar_t* str, size_t len) noexcept; | (5) | (since C++17) |
Forms a string view of a character literal.
std::string_view{str, len}
std::u8string_view{str, len}
std::u16string_view{str, len}
std::u32string_view{str, len}
std::wstring_view{str, len}
str | - | pointer to the beginning of the raw character array literal |
len | - | length of the raw character array literal |
The string_view literal.
These operators are declared in the namespace std::literals::string_view_literals
, where both literals
and string_view_literals
are inline namespaces. Access to these operators can be gained with using namespace std::literals
, using namespace std::string_view_literals
, and using namespace std::literals::string_view_literals
.
#include <string_view> #include <iostream> int main() { using namespace std::literals; std::string_view s1 = "abc\0\0def"; std::string_view s2 = "abc\0\0def"sv; std::cout << "s1: " << s1.size() << " \"" << s1 << "\"\n"; std::cout << "s2: " << s2.size() << " \"" << s2 << "\"\n"; }
Possible output:
s1: 3 "abc" s2: 8 "abc^@^@def"
constructs a basic_string_view (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/string/basic_string_view/operator_q__q_sv