1: // Filename: CPPSTR2.CPP 2: // Purpose: Illustrates C++ string objects: input with cin, comparison, 3: // and output with cout 5: #include <iostream> 6: #include <string> 7: using namespace std; 9: #include "PAUSE.H" 11: int main() 12: { 13: cout << endl; 14: cout << "This program illustrates input with cin, " 15: << "comparison, and more output with " << endl 16: << "cout, of C++ string objects. Study the " 17: << "source code while running it. " << endl 18: << "In response to each prompt, enter either " 19: << "two strings, or an end-of-line to quit. " << endl; 20: Pause(0); 22: string s1, s2; 24: cout << "Enter the two strings below: " << endl; 25: cin >> s1 >> s2; cin.ignore(80, '\n'); 27: while (cin) 28: { 29: cout << "The two strings entered and read " 30: << "are on the next two lines:" << endl; 31: cout << s1 << "<<" << endl; 32: cout << s2 << "<<" << endl; 33: Pause(0); 35: // The following three if-statements, written separately here 36: // to show each of the three possibilities in full, would normally 37: // be written as a nested if with an else at the end. 38: if (s1 == s2) 39: cout << "Those two strings were the same."; 40: if (s1 < s2) 41: cout << "The 1st string precedes the " 42: << "2nd string, alphabetically."; 43: if (s1 > s2) 44: cout << "The 2nd string precedes the " 45: "1st string, alphabetically."; 46: cout << endl << endl; 47: Pause(0); 49: cout << "Enter the two strings below: " << endl; 50: cin >> s1 >> s2; cin.ignore(80, '\n'); 51: } 53: cout << endl; 55: return 0; 56: }