c++ - Replace all occurrences of one string with another in a stream of text -
as title says, how replace string string? example: user enter 3 inputs. first input string program replace; second string replace input1; , third string printed out. if: input1 = peanut input2 = coconut input3 = replace peanut replace output: replace coconut replace i have started program can replace words same length. tried searching problem, not understand given solutions since new @ c/c++. char replacing[100]; char replacement[100]; char original[1000]; int count; cin >> replacing; cin >> replacement; while(! cin.eof()) { cin >> original; char * pch; pch = strstr (original, replacing); count = strlen(replacement); strncpy (pch, replacement, count); cout << original << endl; } what about: you first find (if any) occurrence of string use replace substitute occurrence second string here should work: bool replacefirst(string& input, const std::string& tobereplaced, const std::str