Namespaces
Variants
Views
Actions

std::basic_string::c_str

From cppreference.com
 
 
 
std::basic_string
 
const CharT* c_str() const;

Returns a pointer to a null-terminated character array with data equivalent to those stored in the string. The pointer is such that the range [c_str(); c_str() + size()] is valid and the values in it correspond to the values stored in the string with an additional null character after the last position.

Contents

[edit] Notes

The pointer obtained from c_str() may only be treated as a pointer to a null-terminated character string if the string object does not contain other null characters.

Writing to the character array accessed through c_str() is undefined behavior.

Since C++11, c_str() and data() perform the same function.

[edit] Parameters

(none)

[edit] Return value

Pointer to the null-terminated character array 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

noexcept specification:  
noexcept
  (since C++11)

[edit] See also

(C++11)
accesses the first character
(public member function) [edit]
(C++11)
accesses the last character
(public member function) [edit]
returns a pointer to the first character of a string
(public member function) [edit]