题解 | #字符串去特定字符#
字符串去特定字符
https://www.nowcoder.com/practice/d5d0450134db4cb994a1b323a35262da
#include <iostream>
using namespace std;
int main() {
string s;
char c;
while(getline(cin,s)&&cin>>c){
for(auto it = s.begin();it!=s.end();){
if(*it == c)it = s.erase(it);
else it++;
}
cout<<s<<endl;
}
}
// 64 位输出请用 printf("%lld")
for(auto it = s.begin();it!=s.end();)遍历字符串,注意for最后一个位置是空的
erase返回删除的元素下一个位置的迭代器


