您的位置:首页 > 职场人生

面试题---删除串中指定的字符

2017-10-28 17:59 274 查看
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

void del(char *str,char c)
{
char *head = NULL;
char *p = NULL;
head = p = str;

while(*p != '\0')
{
if(*p != c)
{
*str = *p;
str++;
}
p++;
}
*str = '\0';
}

int main()
{
cout<<"输入一个字符串:"<<endl;
char value[256];
cin>>value;
cout<<"输入要删除的字符"<<endl;
char c;
cin>>c;
del(value,c);
cout<<"删除后的结果为:"<<value<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: