/* teststring5.cpp CIS 150 David Klick 7/3/08 This program demonstrates some common string class functions/methods. */ #include #include using std::cin; using std::cout; using std::string; void cont(); int main() { int i; string s1, s2, s3; // get two names from user cout << "Enter a name: "; cin >> s1; cout << "Enter another name: "; cin >> s2; // display what was read in cout << "You entered: " << s1 << ", " << s2 << '\n'; // compare the names if (s1 > s2) cout << s1 << " is greater than " << s2 << '\n'; else if (s1 < s2) cout << s1 << " is less than " << s2 << '\n'; else cout << "You entered the same name twice\n"; // display the lengths cout << "Length of first string is " << s1.length() << '\n'; cout << "Length of second string is " << s2.size() << '\n'; // display each character of s2 for (i=0; isungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); } /* Sample output: Enter a name: Theodore Enter another name: Sandra You entered: Theodore, Sandra Theodore is greater than Sandra Length of first string is 8 Length of second string is 6 S a n d r a You entered: Sandra, Theodore First string is now empty My name is David G. Klick */