字符串去特定字符

特定字符有可能是空格符,那么就不能用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;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14349294.html