str.replace string str = There are two needles in this haystack with needles. ; string str2 = needle ; short found; // let s replace the first needle: str.replace(str.find(str2),str2.length(), preposition ); cout << str << endl;