Life is a bit simpler if you use
string class strings instead of C-style strings because the class design allows you to use relational operators to make the comparisons. This is possible because one can define class functions that “overload,” or redefine, operators. Chapter 12, “Classes and Dynamic Memory Allocation,” discusses how to incorporate this feature into class designs, but from a practical standpoint, all you need to know now is that you can use the relational operators with
string class objects. Listing 5.12 revises Listing 5.11 to use a
string object instead of an array of
// compstr2.cpp -- comparing strings using arrays#include <iostream>#include <string> // string ...