std::basic_string<CharT,Traits,Allocator>::data

Returns a pointer to the underlying array serving as character storage. The pointer is such that the range

# Declarations

const CharT* data() const;

(noexcept since C++11)(constexpr since C++20)

CharT* data() noexcept;

(since C++17) (constexpr since C++20)

# Return value

A pointer to the underlying character storage.

# Example

#include <algorithm>
#include <cassert>
#include <cstring>
#include <string>
 
int main()
{
    std::string const s("Emplary");
    assert(s.size() == std::strlen(s.data()));
    assert(std::equal(s.begin(), s.end(), s.data()));
    assert(std::equal(s.data(), s.data() + s.size(), s.begin()));
    assert('\0' == *(s.data() + s.size()));
}

# See also