Skip to content

Search topics & cppreference

Search all study topics, concept maps, and 6,587 C++ and C reference pages.

std::span<T,Extent>::data

Returns a pointer to the beginning of the sequence.

NotebookLM
constexpr pointer data() const noexcept;
(since C++20)

Returns a pointer to the beginning of the sequence.

Return value

A pointer to the beginning of the sequence.

Example

example.cpp
#include <iostream>
#include <span>
 
int main()
{
    constexpr char str[] = "ABCDEF\n";
 
    const std::span sp{str};
 
    for (auto n{sp.size()}; n != 2; --n)
        std::cout << sp.last(n).data();
}
Output
ABCDEF
BCDEF
CDEF
DEF
EF
F

See also

constructs a span
(public member function)

Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.