Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 . This could cause a write-out-of-bounds error.

...

Code Block
bgColor#ccccff
langcpp
string bs("01234567");
try {
  size_t i = f();
  bs.at(i) = '\0';
}
catch (...) {
  cerr << "Index out of range" << endl;
}

In any case, the behavior of the index operators is unchecked (no exceptions are thrown).

Non-Compliant Code Example

...

STR38-CPP. Use valid references, pointers, and iterators to reference elements of a basic_string objects      07. Characters and Strings (STR)      08. Memory Management (MEM)