// pgm31 // using the C++ string class // 11/21/2016 #include #include #include #include #include using namespace std; int main() { string text; int i; // read in using input stream operator >> cout << "Enter a string: "; cin >> text; // print to screen using << cout << "text is now: " << text << endl; //text[0]='A'; // change ith location using subscripting cout << "which location do you want to change? "; cin >> i; text[i]='*'; cout << "now text is: " << text << endl; string newstring; newstring = text; //assignment cout << "newstring is: " << newstring << endl; // take the length of newstring cout << "the length of " << newstring << " is " << newstring.length() << endl; // can put return value of length function into a var int len; len = text.length(); cout << "length of " << text << " is " << len << endl; text.clear(); // take the length of newstring cout << "the length of " << newstring << " is " << newstring.length() << endl; len = text.length(); cout << "length of " << text << " is " << len << endl; return 0; }