字符串去特定字符

特定字符有可能是空格符,那么就不能用cin读入字符了。

第一个getchar()读取字符,第二个getchar()读取回车防止影响之后getline的读入。

int main()
{
    string s;
    char c;
    while(getline(cin,s))
    {
        c=getchar();
        getchar();

        for(int i=0;i<s.size();i++)
            if(s[i] != c)
                cout<<s[i];
        cout<<endl;
    }
    //system("pause");
    return 0;
}
posted @ 2021-01-30 15:52  Dazzling!  阅读(54)  评论(0编辑  收藏  举报