Proper way to close a file (newbie)


#1

When using FileInputStream at my program start, it seems that the file remains ‘open’ during the execution :

My_Read_File_Function
{
	File inputFile =File(T("C:\\test.txt"));
	FileInputStream* inputTo = inputFile.createInputStream();
	if (inputTo)
	{
		inputTo->read(my_data,sizeof(my_data));
	}
}

Then do I need to delete something at the end of this function ? Some ‘close()’ equivalent ?

Thanks,

Nicolas


#2

Yes, you need to delete that stream object! Apart from the fact that you need to close the file, it’d be a memory leak not to delete it.


#3

working ! thanks Jules…

Nicolas


#4