// Program Strings applies string functions. #include #include using namespace std; int main () { string name = "John Goldwin"; cout << "01234567890123456789" << endl; cout << name << endl; cout << "The length of the name is " << name.length() << endl; cout << "The length of the name is " << name.size() << endl; //substr(start position, the number of characters to be extracted); cout << name.substr(5, 7) << ", " << name.substr(0, 4) << endl; cout << name.substr(5, 7) << ", " << name.substr(0,1) << endl; //The following works fine with any names //int start; //start = name.find(' '); //Find the position of the first space in the string //cout << name.substr(start+1, name.length()-start-1) << ", " << name.substr(0, start) << endl; //cout << name.substr(start+1, name.length()-start-1) << ", " << name.substr(0,1) << endl; return 0; } //Output: //01234567890123456789 //John Goldwin //The length of the name is 12 //The length of the name is 12 //Goldwin, John //Goldwin, J //Press any key to continue . . .