Namespaces
Variants
Actions

std::basic_string_view<CharT,Traits>::data

From cppreference.com
 
 
 
 
constexpr const_pointer data() const noexcept;
(since C++17)

Returns a pointer to the underlying character array. The pointer is such that the range [data()data() + size()) is valid and the values in it correspond to the values of the view.

Contents

[edit] Parameters

(none)

[edit] Return value

A pointer to the underlying character array.

[edit] Complexity

Constant.

[edit] Notes

Unlike std::basic_string::data() and string literals, std::basic_string_view::data() returns a pointer to a buffer that is not necessarily null-terminated, for example a substring view (e.g. from remove_suffix). Therefore, it is typically a mistake to pass data() to a routine that takes just a const CharT* and expects a null-terminated string.

[edit] Example

#include <cstring>
#include <cwchar>
#include <iostream>
#include <string>
#include <string_view>
 
int main()
{
    std::wstring_view wcstr_v = L"xyzzy";
    std::cout <<