Hi I am trying to run a program that will find the word "Son" in a text file and change it into the word "Gun, but apparently it is not working because the function putback() doesn't seem to be putting back the character back into input stream.
Could you find the problem? Thanks in advance!Code:/* This program will attempt to transfer an original file, find all references of a particular word, edit the word and write to a new file */ #include <iostream> #include <cstdlib> #include <fstream> using namespace std; void editword(ifstream&input, ofstream&output); int main() { char outname[21]; ofstream output; ifstream input; input.open("anyfile.txt");//suppose that undecided has already existr if ( input.fail() ) { cout<<"The input file has failed to open!"; exit(1); } cout<<"Please enter a name for the output file:"<<endl; cin>>outname; output.open(outname); if ( output.fail() ) { cout<<"The input file has failed to open!"; exit(1); } editword(input, output); cout<<"Editing has been completed!"<<endl; input.close(); output.close(); return 0; } void editword(ifstream&input, ofstream&output) { char find; input.get(find); while(!input.eof()) { if(find=='S') { input.get(find); { if(find=='o') { input.get(find); { if(find=='n') { output<<"Gun"; } else { input.putback(find); } } } else { input.putback(find); output.put(find); } } } else { output.put(find); } input.get(find); } }