std::basic_string::data
const CharT* data() const;
|
||
Returns pointer to the underlying array serving as character storage.
If empty()
returns false, the pointer is such that the range [data(); data() + size())
is valid and the values in it correspond to the values stored in the string. If empty()
returns true, the pointer is a non-null pointer that should not be dereferenced. (until C++11)
The pointer is such that the range [data(); data() + size()]
is valid and the values in it correspond to the values stored in the string (including the additional null character) even when empty()
returns true. (since C++11)
Contents |
[edit] Notes
Writing to the character array accessed through data
is undefined behavior.
The pointer obtained from data()
should not be considered valid after any non-const operation on the string.
Since C++11, data()
and c_str()
perform the same function.
[edit] Parameters
(none)
[edit] Return value
Pointer to the underlying character storage such that data()[i] == operator[](i) for every i
in [0, size())
. (until C++11)
Pointer to the underlying character storage such that data() + i == &operator[](i) for every i
in [0, size()]
. (since C++11)
[edit] Complexity
Constant.
[edit] Exceptions
[edit] See also
(C++11)
|
accesses the first character (public member function) |
(C++11)
|
accesses the last character (public member function) |
returns a non-modifiable standard C character array version of the string (public member function) |