This member function behaves as operator[] , except that at also performs a range check, throwing an exception of type out_of_range in case that pos is not an actual position in the string.
Parameters
- pos
- Position within the string of the character to be retrieved. Notice that the first character in the string has position 0.
If the position passed is past the end of str, an out_of_range exception is thrown.
size_t is an unsigned integral type.
Return value
The character at the specified position in the string.Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
This code prints out the content of a string character by character using the at member function.
Basic template member declaration
( basic_string<charT,traits,Allocator> )| 1 2 3 4 5 |
|
See also
| string::operator[] | Get character in string (public member function) |
| string::substr | Generate substring (public member function) |
| string::find | Find content in string (public member function) |
| string::replace | Replace part of string (public member function) |
