// This program demonstrates the + operator // concatenate strings -- append one to the other // also demonstrate subscripting [] // We also see the use of the assignment operator = // Summary of operators that work on strings: // +, =, [], relational operators // LAB1 for Today: // Write a program to read in strings (loop) // If the length of the string is > 10 // print "that is long" // otherwise // print "thank you." // time permitting: // do it both allowing spaces and not allowing spaces #include #include using namespace std; int main() { string firstname, lastname, fullname; // initialize a string object string str, str2 = "Good Bye"; string str3; str = "Hello "; cout << "What is your first name? "; cin >> firstname; cout << "What is your last name? "; cin >> lastname; fullname = lastname + ',' + firstname; cout << str << fullname << '!' << endl; cout << "the length of your name is: " << fullname.length()-1 << '.' << endl; string noun; cout << "enter a noun: "; cin >> noun; // same as: noun = noun+"s"; noun += "s"; // Wrong! assigning to a string literal // "S" += noun; cout << "Plural: " << noun << endl; for (int i=0; i> name; } // Wrong: You cannot + two C-strings // string s2 = "Hello " + "to you."; string s="aac"; if (s < "abb") cout << "aac is less than abb"; else cout << "abb is less than aac"; return 0; }