在线文档教程
C++
字符串 | Strings

std::literals::string_view_literals::operator""sv

STD::文字::String[医]视点[医]文字::运算符“SV”

Defined in header
constexpr string_view operator "" sv(const char* str, size_t len) noexcept;(1)(since C++17)
constexpr u16string_view operator "" sv(const char16_t* str, size_t len) noexcept;(2)(since C++17)
constexpr u32string_view operator "" sv(const char32_t* str, size_t len) noexcept;(3)(since C++17)
constexpr wstring_view operator "" sv(const wchar_t* str, size_t len) noexcept;(4)(since C++17)

形成字符文字的字符串视图。

1%29std::string_view{str, len}

2%29std::u16string_view{str, len}

3%29std::u32string_view{str, len}

4%29std::wstring_view{str, len}

参数

str-pointer to the beginning of the raw character array literal
len-length of the raw character array literal

返回值

弦[医]查看文字。

注记

这些运算符在命名空间中声明。std::literals::string_view_literals,两者都是literalsstring_view_literals是内联命名空间。可以通过以下方式访问这些操作员using namespace std::literals,,,using namespace std::string_view_literals,和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"; }

二次

可能的产出:

二次

s1: 3 "abc" s2: 8 "abc^@^@def"

二次

另见

(constructor)constructs a basic_string_view (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/string/basic[医]弦[医]视图/操作员[医]q[医][医]q[医]SV