
please wait
21.3.6 - basic_string string operations [lib.string.ops] const charT* c_str() const; -1- Returns: A pointer to the initial element of an array of length size() + 1 whose first size() elements equal the corresponding elements of the string controlled by *this and whose last element is a null character specified by charT(). -2- Requires: The program shall not alter any of the values stored in the array. Nor shall the program treat the returned value as a valid pointer value after any subsequent call to a non-const member function of the class basic_string that designates the same object as this. const charT* data() const; -3- Returns: If size() is nonzero, the member returns a pointer to the initial element of an array whose first size() elements equal the corresponding elements of the string controlled by *this. If size() is zero, the member returns a non-null pointer that is copyable and can have zero added to it. -4- Requires: The program shall not alter any of the values stored in the character array. Nor shall the program treat the returned value as a valid pointer value after any subsequent call to a non- const member function of basic_string that designates the same object as this. |
21.4.7.1 basic_string accessors [string.accessors] const charT* c_str() const; const charT* data() const; 1 Returns: a pointer p such that p + i == &operator[](i) for each i in [0,size()]. 2 Throws: nothing. 3 Complexity: constant time. 4 Requires: The program shall not alter any of the values stored in the character array. |
So, how would one produce a C string in this set-up - write the terminating null character manually (through push_back) or what? I don't know. |
const_reference operator[](size_type pos) const; reference operator[](size_type pos); 1 Requires: pos <= size(). 2 Returns: *(begin() + pos) if pos < size(), otherwise a reference to an object of type T with value charT(); the referenced value shall not be modified. 3 Throws: nothing. |
Sometimes I have the feeling the C++ standard is intently vague in order to avoid stepping on someone's toes. |