int index0f (const string& s1, const string& s2)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 11SA
icon
Related questions
Question
**6.43 (Check substrings) Write the following function to check whether string sl is
a substring of string s2. The function returns the first index in s2 if there is a
match. Otherwise, return -1.
int index0f (const string& s1, const string& s2)
Write a test program that reads two strings and checks whether the first string is
a substring of the second string. Here is a sample run of the program:
Enter the first string: welcome -Enter
Enter the second string: We welcome you! -Enter
index0f ("welcome", "We welcome you!") is 3
Enter the first string: welcome
Enter the second string: We invite you!
index0f ("welcome", "We invite you!") is -1
JEnter
- Enter
Transcribed Image Text:**6.43 (Check substrings) Write the following function to check whether string sl is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. int index0f (const string& s1, const string& s2) Write a test program that reads two strings and checks whether the first string is a substring of the second string. Here is a sample run of the program: Enter the first string: welcome -Enter Enter the second string: We welcome you! -Enter index0f ("welcome", "We welcome you!") is 3 Enter the first string: welcome Enter the second string: We invite you! index0f ("welcome", "We invite you!") is -1 JEnter - Enter
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning