std::basic_string<CharT,Traits,Allocator>::at
From cppreference.com
< cpp | string | basic string
CharT& at( size_type pos ); |
(1) | (constexpr since C++20) |
const CharT& at( size_type pos ) const; |
(2) | (constexpr since C++20) |
Returns a reference to the character at specified location pos. Bounds checking is performed, exception of type std::out_of_range will be thrown on invalid access.
Contents |
[edit] Parameters
pos | - | position of the character to return |
[edit] Return value
Reference to the requested character.
[edit] Exceptions
Throws std::out_of_range if pos >= size().
If an exception is thrown for any reason, these functions have no effect (strong exception safety guarantee).
[edit] Complexity
Constant.
[edit] Example
Run this code
#include <iostream> #include <stdexcept> #include <string> int main() {