libstdc++
GNU C++ library
Loading...
Searching...
No Matches

◆ at() [2/4]

template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::at ( size_type __n)
inline

Provides access to the data contained in the string.

Parameters
__nThe index of the character to access.
Returns
Read/write reference to the character.
Exceptions
std::out_of_rangeIf n is an invalid index.

This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. Success results in unsharing the string.

Definition at line 1192 of file cow_string.h.

1193 {
1194 if (__n >= size())
1195 __throw_out_of_range_fmt(__N("basic_string::at: __n "
1196 "(which is %zu) >= this->size() "
1197 "(which is %zu)"),
1198 __n, this->size());
1199 _M_leak();
1200 return _M_data()[__n];
1201 }
#define __N(msgid)
void __throw_out_of_range_fmt(const char *,...)
constexpr size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
constexpr pointer _M_data() const
Managing sequences of characters and character-like objects.