Yes. Per the C++0x FDIS 21.4.7.1/1, std::basic_string::c_str()
must return
a pointer
p
such thatp + i == &operator[](i)
for eachi
in[0,size()]
.
This means that given a string s
, the pointer returned by s.c_str()
must be the same as the address of the initial character in the string (&s[0]
).
More Related Contents:
- Why is modifying a string through a retrieved pointer to its data not allowed?
- Is writing to &str[0] buffer (of a std:string) well-defined behaviour in C++11?
- A positive lambda: ‘+[]{}’ – What sorcery is this? [duplicate]
- reinterpret_cast creating a trivially default-constructible object
- Why is conversion from string constant to ‘char*’ valid in C but invalid in C++
- Why would the behavior of std::memcpy be undefined for objects that are not TriviallyCopyable?
- Is the size of std::array defined by standard
- Capturing a reference by reference in a C++11 lambda
- Split a string using C++11
- Why are strings in C++ usually terminated with ‘\0’?
- How do I properly use std::string on UTF-8 in C++?
- Do I really need to implement user-provided constructor for const objects?
- In C++11, does `i += ++i + 1` exhibit undefined behavior?
- Is std::abs(0u) ill-formed?
- Why does the standard differentiate between direct-list-initialization and copy-list-initialization?
- What does the void() in decltype(void()) mean exactly?
- Can the point-of-instantiation be delayed until the end of the translation unit?
- C++: Can a macro expand “abc” into ‘a’, ‘b’, ‘c’?
- What is the value category of the operands of C++ operators when unspecified?
- How can an incomplete type be used as a template parameter to vector here?
- Is a constexpr array necessarily odr-used when subscripted?
- Is the Empty Base Class Optimization now a mandatory optimization (at least for standard-layout classes)?
- Classes with both template and non-template conversion operators in the condition of switch statement
- Using std::string_view with api that expects null-terminated string
- reinterpret_cast between char* and std::uint8_t* – safe?
- What is the difference between std::quick_exit and std::abort and why was std::quick_exit needed?
- Does C++11 change the behavior of explicitly calling std::swap to ensure ADL-located swap’s are found, like boost::swap?
- Using std::bind with member function, use object pointer or not for this argument?
- memcpy/memmove to a union member, does this set the ‘active’ member?
- Overload resolution with ref-qualifiers