Last comment of Remy Lebeau for previous answer worked to me - "don't declare the ifstream as a global variable". I just made a few local variables like
ifstream
ofstream flog;