Fstream file closing


ofstream newFile(fileName); 
for(int i = 0; i <= fileLines; i++) {
    newFile << fileCode[i] + "\n"; 

Above, if any code is executed after the newFile.close(), it will give an error:

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_M_construct null not valid 

Does anyone know why this is happening and how to fix this?

(this also might be with my code, so if this error does not occur when you try this, check my project above)