REPLACE WORDS IN A STRING

Description:

Take a string as input from the user. Take two words as input, the word which the user wants to replace and its substitute Test Case 1 Input (stdin) SRMuniveristychennai chennai potheri Expected Output SRMuniveristypotheri Test Case 2 Input (stdin) Britishrockband British American Expected Output Americanrockband

Program :

#include <iostream>

#include <string.h>

using namespace std;

int main()

{

  string s;

    char m[50],n[50];

  getline(cin,s);

    cin>>m>>n;

    while (s.find(m) != string::npos)

        s.replace(s.find(m),strlen(m),n);

    cout << s << endl;

    return 0;

}