My question is that if I want to run a C++ program, which needs to input two things:
string
A
,string
B
,
the Program's purpose is to remove all occurrences of B
from A
.
Ex: A = adferttyu
, B = adf
Output: erttyu
.
My question is that if I want to run a C++ program, which needs to input two things:
string A
,
string B
,
the Program's purpose is to remove all occurrences of B
from A
.
Ex: A = adferttyu
, B = adf
Output: erttyu
.
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