Why is it that I calling the ifstream and ofstream objects in the same scope causes the program below to misbehave by not reading up to end of file or not writing anything to the output file. The program reads an input file called Smart.txt and it writes something to an output file called Great.txt and if the word NAMES is encountered in the input file, it writes something to a file called Temp.txt and at thesame time under this condition opens the Great.txt as input file in which it reads and searches a line containing the word "people" and displays the line number. But unfortunately, once NAMES is met, then all other words from the Smart.txt would not be read. WHY THIS? PLEASE SOMEONE SHOULD HELP. HERE IS THE CODE BELOW;
int searchString(std::ifstream& in_stream, std::string people){
std::string input;
int number = 0;
for (int i = 0; getline(fin, input); i++){
number++;
if (input.find(people) != std::string::npos){