#include <string>
string firstname; string lastname string address; string s1;
firstname = "Joe"; lastname = "Schmuckatelli"; address = "123 Main St."; s1 = firstname; // s1 is now "Joe" also
string s2 = "How are you?"; string s3 = "I am fine."; string s4 = "The quick brown duck jumped over the lazy octopus";
string fname("Marvin"); string lname("Dipwart"); string s2(s1); // s2 is created as a copy of s1
if (s1 == s2) cout << "The strings are the same"; if (s1 < s2) cout << "s1 comes first lexicograpically";
if (s1 == "Joe") cout << "The first student is Joe"; if (s2 > "apple") cout << "s2 comes after apple in the dictionary";
string s1 = "Fish"; string s2 = "bait"; string s3; s3 = s1 + s2; // s3 is now "Fishbait"
string s4 = s3 + " odor"; // s4 is now "Fishbait odor"
string t1 = "Bird"; string t2 = "Boogie"; t1 += "brain"; // t1 is now "Birdbrain" t1 += " "; t1 += t2; // t1 is now "Birdbrain Boogie"
string s1 = "Hello, world"; string s2 = "Goodbye, cruel"; cout << s1; // prints "Hello, world" cout << s2 + " world"; // prints "Goodbye, cruel world"
string s3; cin >> s3; // will read one word
char address[30]; // c-string string addr; // string object cin.getline(address, 30); // reads up to newline, for c-string getline(cin, addr); // reads up to newline, for string object cin.getline(address, 30, ','); // reads up to comma, for c-string getline(cin, addr, ','); // reads up to comma, for string object
string s1 = "Apple pie and ice cream"; cout << s1[0]; // prints 'A' cout << s1[4]; // prints 'e' s1[4] = 'y'; s1[8] = 'g'; cout << s1; // prints "Apply pig and ice cream"
string s1 = "Greetings, earthling"; string s2 = s1.substr(11,5); // s2 is now "earth" string s3 = s1.substr(4); // s2 is now "tings, earthling"