home *** CD-ROM | disk | FTP | other *** search
-
- #include <iostream.h>
- #include <cstring.h>
-
- int main()
- {
- int result;
-
- string &s1 = * new string; // create 2 references to string
- string &s2 = * new string;
- string message; // create an instance of a string
-
- while (1) // run this loop forever
- {
- cout << "Enter two lines of text, \"end\" to end program\n";
- getline(cin, s1); // read a line into s1 from the keyboard
-
- if (s1 == "end") // If ending the program is requested
- break; // break out of the loop
-
- getline(cin, s2); // read a line into s2
-
- if (s2 == "end") // If ending the program is requested
- break; // break out of the loop
-
- result = s1.compare(s2); // get and save comparison result
-
- if (result == 0) // save what we've found in "message"
- message = "The strings are equal";
- else if (result > 0)
- message = "The first string is greater";
- else
- message = "The second string is greater";
-
- cout << message << endl << endl; // report the result
- }
-
- delete &s1; // References are handled in source code as if they
- delete &s2; // were actual items. This is why the '&' operator
- return 0; // is used to get their address for use by
- } // delete.
-
-