The index operators:
Code Block |
---|
const_reference operator[](size_type pos) const; reference operator[](size_type pos); |
...
The behavior of this non-compliant example is undefined because the index i
used to reference bs
may be outside the range of bs
, causing a write-out-of-bounds error.
...
Wiki Markup |
---|
This compliant solution uses the {{basic_string at()}} method, which behaves in a similar fashion to the index {{operator\[\]}} but throws an {{out_of_range}} exception if {{pos >= size()}}. |
...