| (1) | |||
| (2) |
Returns a reference to the character at specified location pos
. No bounds checking is performed.
1) If pos == size() , the behavior is undefined. 2) If pos == size() , a reference to the character with value CharT() (the null character) is returned. | (until C++11) |
If For the first (non-const) version, the behavior is undefined if this character is modified. | (since C++11) |
Parameters
pos | - | position of the character to return |
Return value
Reference to the requested character.
Complexity
Constant.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream> #include <string> int main() { { std::string const c( "Exemplar" ); for (unsigned i = 7;i != 0; i/=2) std::cout << c[i]; } std::cout << '\n' ; { std::string s( "Exemplar " ); s[s.size()-1] = 'y' ; std::cout << s; } } |
Output:
1 2 | rmx Exemplary |
See also
access specified character with bounds checking (public member function) |
Please login to continue.