Consider the following statement: string str = \"Now is the time for the party!\
ID: 3625120 • Letter: C
Question
Consider the following statement:string str = "Now is the time for the party!";
What is the output of the following statements? (Assume that all parts are independent of each other.)
a.) cout << str.size() << endl;
b.) cout << str.substr (7, 8) << endl;
c.) string: : size_type ind = str.find ('f');
string s = str.substr (ind + 4, 9);
cout << s << endl;
d.) cout << str.insert (11, "best ") << endl;
e.) str.erase (16, 14);
str.insert (16, "to study for the exam?");
cout << str << endl;
Explanation / Answer
please rate - thanks
a.) cout << str.size() << endl; 30 which is the length of the string
b.) cout << str.substr (7, 8) << endl; the time start at string index 7 and get 8 characters
c.) string: : size_type ind = str.find ('f'); the party look for the f and starting 4 characters after
string s = str.substr (ind + 4, 9); get nine characters
cout << s << endl;
d.) cout << str.insert (11, "best ") << endl; now is the best time for the party! at index 11 add best
e.) str.erase (16, 14);
str.insert (16, "to study for the exam?"); now is the best to study for the exam? starting at character
cout << str << endl; 16 remove 14 characters. this removes time for the party
then inserts at that same spot to study for the exam?