// Mr. Minich
// Computer Science Using C++
// Ch. 6 Demo Program #2
// January 30, 2000 // Purpose - to illustrate a potential error with the use of string variables.

#include <iostream.h> #include "M:\C++ Programming\AP classes\apstring.h" int main() { apstring firstName = "Jane"; // user's first name cout << "The fourth letter of your name is: " << firstName[3] << endl; firstName[5] = 't'; cout << "Your name is " << firstName << endl; // The assignment of the character 't' to the 6th position of firstName
// could cause a Windows error message like the window below.
return 0; }// end of main

The program causes a "friendly", index-out-of-range runtime error that is produced by the apstring class.

However, if built-in C++ character arrays were used the error would result in a scary runtime error message like the one below.