Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using std::cin; using std::cout; using std::endl; using std::string;
- void substr_delete(string &s, const string &del);
- int main(void)
- {
- string str = "Authentic Symphony", substr = "then";
- substr_delete(str, substr);
- cout << str << endl;
- return 0;
- }
- void substr_delete(string &s, const string &del)
- {
- for (string::iterator beg = s.begin();
- beg != s.end();
- ++beg) {
- string::const_iterator begov = del.begin();
- if (*beg == *begov) {
- string::iterator pos = beg;
- string::size_type cnt = 0;
- for (string::iterator copybeg = beg;
- copybeg != s.end() && begov != del.end();
- ++copybeg, ++begov) {
- if (*copybeg == *begov)
- ++cnt;
- }
- if (cnt == del.size()) {
- beg = s.erase(pos, pos + cnt);
- --beg;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement