View Code of Problem 3496

#include<iostream>
#include<string>

using namespace std;

int main() {
    string s;
    int p;
    while (getline(cin, s)) {
        p = s.find("you");
       while (p!=-1) {//find查找不成功返回-1,replace要用str替换指定字符串从起始位置pos开始长度为len的字符 
        //   *string& replace(size_t pos, size_t len, const string & str);
           s.replace (p, 3, "we");
           p = s.find("you");
        }
        cout << s << endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 3496