Question: B. Searching in a String In this program, you will use a string function to determine whether a user selected sub- string is present in

 B. Searching in a String In this program, you will use

B. Searching in a String In this program, you will use a string function to determine whether a user selected sub- string is present in a larger string or not. 1. Declare and initialize a string with the following text: This is a lab in CSCE 1030 based on strings. 2. Declare another string variable to store the sub-string you want to search in the larger string. 3. Using a suitable message, ask the user for the sub-string. You many assume the user will only enter a single word to search. 4. Using the member function find(), determine the location of the sub-string in the larger string. 5. Inside an if-else block, check if the computed location is a valid index. a. If it is a valid index, display the location of the substring with a suitable message. Note at just comparing the location with -1 is not sufficient. Think what the valid range indices for a string is and use that in your if-else condition. b. If it is not a valid index, display a suitable error message

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!