In: Computer Science
THE NOT REPLACE PROBLEM
Must use loops. Please do not use sequence of if statements.
I need it in C++.
Given an input string, set result to a string where every appearance of the lowercase word "is" has been replaced with "is not". The word "is" should not be immediately preceded or followed by a letter -- so for example the "is" in "this" does not count.
• for input of "is test" → "is not test"
• for input of "is-is" → "is not-is not"
• for input of "This is right" → "This is not right"
PROGRAM :
#include <iostream>
#include <string>
// importing regex module for regular expression
#include <regex>
using namespace std;
int main() {
string text;
cout << "Please enter the input string : ";
// getline() to input a string ot a sentence
getline(cin,text);
// \b acts as word boundary
// regex variable 'e' is initialized based on the question which
matches for 'is' inside any statement
std::regex e("\\b(is)\\b");
// replace 'is' with 'is not'
cout<<"The replaced string is : " +
std::regex_replace(text,e,"is not");
}
OUTPUT :