• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
August 10, 2022 |500 Views
C++ Program to Delete Word from a String
Description
Discussion

In this video, we will write a C++ program to delete words from strings.

Method
Step 1: Get the String and the word to be deleted. 
Step 2: Get the length of the original string using length(). 
Step 3: Now, do 
string lefthalf = sentence.substr(0,start); 
string righthalf = sentence.substr(start+s.length()); 
Step 4: Print a new string.

Examples: 
Input: “Hello, how are you?” 
Word: “How” 
Output= “Hello are you?” 

Input: “I am a CSE 3rd-year student.” 
Word: “CSE” 
Output:” I am a 3rd-year student.” 

Read More