CISC 1110 Lab 19
Write a C++ program which works with strings. The program will perform some elementary operations using the string member functions. Run the program.
In the program, declare a few string variables – enough to do the steps requested below. Start by assigning values to each of the strings, either in the declaration or by assignment.
a. using either length() or size(), find the number of character stored in one of your strings. Print the result, with a message that includes the string name.
b. do a successful find() operation, starting at position 0 of one of your strings. Print a message showing the string searched for, the string you searched, and the position in which it was found.
c. do a find() starting at 0, but search for a string that is not found. Print a message showing the string searched for, the string you searched, and the "not found" message. Use string::npos to show that the string is not found.
d. do an insert() operation. Print the string with a message before and after you insert some characters.
e. do an erase() operation. Print the string with a message before and after you delete some characters.
f. do a substr() operation, taking a few characters from the middle of a string. Print the resulting substring, with a message.
g. do a substr() operation, taking all remaining characters from a specified point to the end of the string. Print the resulting substring, with a message.
h. do a successful replace() operation, replacing one string of characters in the string with another set. Print the string with a message before and after the call to replace().
i. Print one of your strings. Then change a few individual positions in the string. Print the new string as a whole; then use a loop to print the characters in the string, one char at a time, each on a new line.
j. Add "son" to the end of one of your strings. Print the resulting string.
k. Read in a string with spaces using getline. Print the string read in.