FreeBSD Manual Pages
std::basic_string::data(3) C++ Standard Libary std::basic_string::data(3) NAME std::basic_string::data - std::basic_string::data Synopsis const CharT* data() const; (until C++11) const CharT* data() const noexcept; (since C++11) (until C++20) constexpr const CharT* data() const noexcept; (1) (since C++20) CharT* data() noexcept; (since C++17) (2) (until C++20) constexpr CharT* data() noexcept; (since C++20) Returns a pointer to the underlying array serving as character stor- age. The pointer is such that the range [data(); data() + size()) (until C++11) [data(); data() + size()] (since C++11) is valid and the values in it correspond to the values stored in the string. The returned array is not required to be null-terminated. (un- til C++11) If empty() returns true, the pointer is a non-null pointer that should not be dereferenced. The returned array is null-terminated, that is, data() and c_str() perform the same function. (since C++11) If empty() returns true, the pointer points to a single null character. The pointer obtained from data() may be invalidated by: * Passing a non-const reference to the string to any standard li- brary function, or * Calling non-const member functions on the string, excluding op- erator[](), at(), front(), back(), begin(), end(), rbegin(), rend(). 1) Modifying the character array accessed through the const overload of data has undefined behavior. 2) Modifying the past-the-end null terminator stored at data()+size() to any value other than CharT() has undefined behavior. Parameters (none) Return value A pointer to the underlying character storage. data()[i] == operator[](i) for every i in [0, size()). (until C++11) data() + i == std::addressof(operator[](i)) for every i in [0, (since C++11) size()]. Complexity Constant. Example // Run this code #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 front accesses the first character (C++11) (public member function) back accesses the last character (C++11) (public member function) c_str returns a non-modifiable standard C character array version of the string (public member function) data returns a pointer to the first character of a view (C++17) (public member function of std::ba- sic_string_view<CharT,Traits>) http://cppreference.com 2022.07.31 std::basic_string::data(3)
NAME | Synopsis | Parameters | Return value | Complexity | Example | See also
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::u32string::data&sektion=3&manpath=FreeBSD+Ports+15.0>
