Write a program to practice how to use
length(), find() and substr() funcitons. You need to understand the first exercise before this one.
Following the steps gave bellow:
- Declare a string varible: OriginalString.
- Assign "And now for something completely different."
to the OriginalString.
- Display the length of the OriginalString.
- Find and display the position of "completely" in the OriginalString.
- Declare a string variable: NewString.
- Use the substr() funciton to get a sub-string of the OriginalString as "And now for something ".
and then assign it to the NewString.
- Output the NewString.
- Get a sub-string of OriginalString with value "different.".
Add this substring to the NewString.
- Display the NewString.
The output should be something like the following:
And now for something different.
- Compile and run this C++ program.
- Show your lab instructor the program output.
Copyright: Department of Computer Science, University of Regina.