-3

My question is that if I want to run a C++ program, which needs to input two things:

  1. string A,

  2. string B,

the Program's purpose is to remove all occurrences of B from A.

Ex: A = adferttyu, B = adf

Output: erttyu.

User_Targaryen
  • 4,125
  • 4
  • 30
  • 51
starsneverfall
  • 137
  • 1
  • 2
  • 15
  • Could you share what you've tried? – sokkyoku Oct 05 '16 at 12:38
  • 5
    https://en.wikipedia.org/wiki/Question – LogicStuff Oct 05 '16 at 12:38
  • What is your question ? What you give us is question that someone asked _you_. So what have you already tried to answer it? – Garf365 Oct 05 '16 at 12:41
  • 1
    Possible duplicate of [How to remove all substrings from a string](http://stackoverflow.com/questions/32435003/how-to-remove-all-substrings-from-a-string) – User_Targaryen Oct 05 '16 at 12:51
  • I think you don't want to run a C++ program (If I got your question correctly). – Ped7g Oct 05 '16 at 13:37
  • Please [edit] your question to show [what you have tried so far](http://whathaveyoutried.com). You should include a [mcve] of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Oct 05 '16 at 16:45
  • Perhaps there's an implementation of sed in C++. That would certainly achieve your aims if it exists. – Toby Speight Oct 05 '16 at 16:46

1 Answers1

0

This removes all substrings from a string

#include <string>
#include <iostream>

using namespace std;

void removeSubstrs(string& s, string& p) { 
  string::size_type n = p.length();
  for (string::size_type i = s.find(p);
      i != string::npos;
      i = s.find(p))
      s.erase(i, n);
}

int main() {

  string A = "adferttyu";
  string B = "adf";

  removeSubstrs(A, B);
  cout << A << endl;
}

Output: erttyu

User_Targaryen
  • 4,125
  • 4
  • 30
  • 51