(N) Matching a string

Goal: I will practice using C++ strings and control structures (if statements and loop structures).

Instructions: Create a new project: student/01/string_find.

Assignment

Implement a program that asks for two strings and finds out, if the latter one is included in the former one. If this is not the case, the program prints Not found.

The latter string can be included in the former one several times. The program prints all occurrences separated by a comma.

Below you can see example executions of the program.

Enter a (longer) string: preprocessor
Enter a (shorter) string to be found: pro
Found at 3
Enter a (longer) string: preprocessor
Enter a (shorter) string to be found: pr
Found at 0, 3
Enter a (longer) string: preprocessor
Enter a (shorter) string to be found: press
Not found
Enter a (longer) string: processor
Enter a (shorter) string to be found: preprocessor
Not found

Tips for completing the assignment:

  • You can use different string operations such as at, find, substr.

  • Can you implement the program without using ready-made find?

A+ presents the exercise submission form here.