fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string s = "quick brown frog jumps over the lazy dog";
  7. size_t start = -1;
  8. int cnt = 3; // Word number three
  9. do {
  10. start = s.find(' ', start+1);
  11. } while (start != string::npos && --cnt > 1);
  12. size_t end = s.find(' ', start+1);
  13. s.replace(start+1, end-start-1, "fox");
  14. cout << s << endl;
  15. return 0;
  16. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
quick brown fox jumps over the lazy dog