   Question on opening IFSTREAM file
  In my program, I access a function that opens a file, multiple times.The first time it tries to access the file, it works. But the second time it comes back around to access the file it returns NULL as if it couldn't find the file.ifstream playerIFile[100];playerIFile[iPlayers].open(players[iPlayers].username);if(!playerIFile[iPlayers]){cout<<"Couldn't find file";}playerIFile[iPlayers].close();I've even checked this by printing the filename to the screen. Even though the filename it's opening is EXACTLY the same both times, the second time returns NULL and therefore "couldn't find file".Any help is greatly appreciated,Chris   
  Solved it.I guess I had to use the clear() function before opening   ;Quote:Original post by Chris Reynoldsifstream playerIFile[100];Why?   ;  Good question.Sometimes my brain's logic takes a vacation, thanks for catching that   ;  Use the constructor to open a file stream, and let the destructor close it. Since you should already be declaring variables in the tightest scope possible (i.e. near first use), you should automatically get the stream re-opened each time, because an entirely new object is created each time.for (int i = 0; i < NUM_PLAYERS; ++i) {  // Every time the loop reaches this point, a brand new ifstream is constructed  // for the new file.  ifstream playerIFile(players.username);  if (!playerIFile) {    cout<<"Couldn't find file";  }  doStuffWith(playerIFile);  // Every time the loop reaches this point, the destructor is called for the  // ifstream, which automatically closes the file.}