编写一个函数,能清除字符串中出现的#字符erase("he##1#hel#llo")--"hello"
void show(string a)
{
for (int i = 0; iif (a[i] =='#')
{
auto b = a.begin();
a.erase(i);
}
}
cout << a << endl;
}
int main()
{
string a = "he##1#hel#llo";
show(a);
}
he
erase 删除函数将‘#’后面的字符全部删掉了 不知道还有没有更好的接替方法
不用erase的话,可以用定义一个string c="";在循环中,不是#字符的放到c中,最后输出c