Namespaces
Variants
Views
Actions

std::basic_string::operator[]

From cppreference.com
 
 
 
std::basic_string
 
reference       operator[]( size_type pos );
const_reference operator[]( size_type pos ) const;

Returns a reference to the character at specified location pos. No bounds checking is performed.

If pos==size(),

  • The const version returns a reference to the character with value CharT() (the null character). (until C++11)
  • Both versions returns a reference to the character with value CharT() (the null character). Modifying the null character through non-const reference results in undefined behavior. (since C++11)

Contents

[edit] Parameters

pos - position of the character to return

[edit] Return value

reference to the requested character

[edit] Complexity

Constant

[edit] See also

access specified character with bounds checking
(public member function) [edit]