C++ String Exercises: Remove a word from a given string
34. Remove a Specific Word from a String
Write a C++ program that removes a specific word from a given string. Return the updated string.
Test Data:
("Exercises Practice Solution", "Solution") -> "Exercises Practice"
("Exercises Practice Solution", "Practice ") -> "Exercises Solution"
("Exercises Practice Solution", " Solution") -> " Practice Solution"
Sample Solution:
C++ Code:
Sample Output:
String: Exercises Practice Solution Word to remove: Solution New string, after removing the said word: Exercises Practice String: Exercises Practice Solution Word to remove: Practice New string, after removing the said word: Exercises Solution String: Exercises Practice Solution Word to remove: Exercises New string, after removing the said word: Practice Solution
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C++ program to remove all instances of a given word from a sentence and output the modified string.
- Write a C++ program that reads a sentence and a target word, then deletes the target word wherever it appears.
- Write a C++ program to search for a specific word in a string and remove it, adjusting spaces appropriately.
- Write a C++ program to process a string and replace a designated word with an empty string, then print the result.
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous C++ Exercise: Check first string contains letters from the second.
Next C++ Exercise: Reverse the words in a string that have odd lengths.What is the difficulty level of this exercise?