-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.cpp
31 lines (23 loc) · 909 Bytes
/
2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
// Function to remove a given word from a string
std::string removeWordFromString(const std::string& input, const std::string& wordToRemove) {
std::string result = input;
size_t found = result.find(wordToRemove);
while (found != std::string::npos) {
// Erase the found word from the string
result.erase(found, wordToRemove.length());
// Search for the next occurrence
found = result.find(wordToRemove, found);
}
return result;
}
int main() {
std::string inputString = "vinayak and trepankar";
std::string wordToRemove = "and";
// Call the function to remove the word
std::string modifiedString = removeWordFromString(inputString, wordToRemove);
std::cout << "Original String: " << inputString << std::endl;
std::cout << "Modified String: " << modifiedString << std::endl;
return 0;
}