##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

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

From cppreference.com
< cpp‎ | string‎ | basic string view

Defined in header `<string_view>` |  |
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)

Forms a string view of a character literal.

1) returns std::string_view{str, len}
2) returns std::u16string_view{str, len}
3) returns std::u32string_view{str, len}
4) returns std::wstring_view{str, len}

### [edit] Parameters

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

### [edit] Return value

The string_view literal.

### [edit] Notes

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.

### [edit] Example

Run this code

    #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"

### [edit] See also

(constructor) | constructs a `basic_string_view` (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/string/basic_string_view/operator%22%22sv&oldid=90102"