字符串替换,string的强大

#include"iostream"
#include"string"
using namespace std;
int main()
{
    string str;
    while(getline(cin,str))
    {
        string::size_type k;
        while((k=str.find("you"))!=string::npos){
            str.replace(k,3,"we");
        }
        cout<<str<<endl;
    }
    return 0;
}

posted @ 2011-06-13 07:38  dzqabc  阅读(257)  评论(0编辑  收藏  举报