How to close a IFstream?
Hello,
I have a short question. I wrote my own converter for some field and I opened a file to read in some values: fileName dataFile; laserToFoamDict.lookup("datafile") >> dataFile; IFstream dataStream(dataFile); dataStream >> value; Now after reading I want to close the file. How do I close this file? kind regards, Fabian |
Is it not just
Code:
dataStream.close(); |
No unfortunately not.
dataStream.close() give the following error: error: ‘class Foam::IFstream’ has no member named ‘close’ kind regards, Fabian |
Quote:
Normally you don't need to explicitly close OpenFOAM streams - just let them go out of scope and let the destructor do it for you. You won't be able to a normal close() method on the IFstream, since the std::istream is private. AFAICT this probably helps with handling both normal and gz files, but it doesn't really matter. The simplest means to handle what you want is something like this small workaround (not tested): Code:
fileName dataFile; Code:
dataStream.stdStream().close(); |
Allright, I am more used to the Fortran language and there is good style to close a file after one has finished working with it. I thought I have to do this too in C++, but as you mentioned the destructor will handle this for me. I will accept this. I tried quickly:
Code:
dataStream.stdStream().close(); Thx for your help. kind regards, Fabian |
Quote:
You'd need to dynamic_cast the std::istream reference returned by the stdStream() method to the std::ifstream reference that it actually is ... if someone really needed to go that route. |
All times are GMT -4. The time now is 15:34. |