面试题---删除串中的指定子串

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>

using namespace std;


void del(char *str,char *sub)
{
    char *head = NULL;
    char *p = NULL;
    head = p = str;
    int sublen = strlen(sub);

    while(*p != '')
    {
        if(strncmp(p,sub,sublen) != 0)
        {
            *str = *p;
            str++;
        }
        else
        {
            p--;
            p += sublen;
        }
        p++;
    }

    *str = '';
}

int main()
{
    cout<<"输入一个字符串:"<<endl;
    char value[256];
    cin>>value;
    cout<<"输入要删除的字符串"<<endl;
    char sub[256];
    cin>>sub;
    del(value,sub);
    cout<<"删除后的结果为:"<<value<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/qingergege/p/7747579.html