std::basic_string<CharT,Traits,Allocator>::operator[] (3) - Linux Manuals
std::basic_string<CharT,Traits,Allocator>::operator[]: std::basic_string<CharT,Traits,Allocator>::operator[]
NAME
std::basic_string<CharT,Traits,Allocator>::operator[] - std::basic_string<CharT,Traits,Allocator>::operator[]
Synopsis
reference operator[]( size_type pos ); (1)
const_reference operator[]( size_type pos ) const; (2)
Returns a reference to the character at specified location pos. No bounds checking is performed. If pos > size(), the behavior is undefined.
1) If pos == size(), the behavior is undefined. (until C++11)
2) If pos == size(), a reference to the character with value CharT() (the null character) is returned.
If pos == size(), a reference to the character with value CharT() (the null character) is returned. (since C++11)
For the first (non-const) version, the behavior is undefined if this character is modified to any value other than CharT() .
Parameters
pos - position of the character to return
Return value
Reference to the requested character.
Complexity
Constant.
Example
// Run this code
Output:
See also
at (public member function)