123456789101112131415161718192021222324
#include <fstream> #include <string> int main() { std::ifstream fin("input.txt"); std::ofstream fout("output.txt"); std::string oldWord("here"); std::string newWord("there"); std::string line; while( fin.good() ) { getline( fin, line); size_t pos = line.find( oldWord ); if (pos != std::string::npos) line.replace(pos, oldWord.size(), newWord) fout << line << std::endl; } return 0; }