using at() with strings

C++ strings provide an alternative to the s[n] notation: the at( ) member. These two idioms produce the same result in C++.
There is an important difference is when you try to reference an array element that is out of bounds, at( ) will do you the kindness of throwing an exception, while ordinary [ ] subscripting syntax will be undefined behaviour. Example:

#include <string>
#include <iostream>
using namespace std;
int main()
    string s("123456789");
    // Runtime problem: goes beyond array bounds:
    cout << s[5] << endl;
    cout << << endl; // ok
    cout << << endl; // throw exception
    return 0;