Ifstream

Ifstream

ifstream is the C++ standard library class that provides an interface to read data from files as input streams.

To use the ifstream class, fstream library (header file) must be included using the preprocessor directive: #include

The input stream may open a file in the constructor:

ifstream inf("input.dat", ifstream::in);

or afterwards:

ifstream inf;inf.open("input.dat");

To close a stream, one uses the close method:inf.close();

The ifstream destructor will close the file cleanly as well. It is perfectly acceptable to allow the ifstream object to fall out of scope without calling close. This is often a desirable style, as it simplifies the "clean up" process when an exception is thrown or an error is otherwise encountered.

References

[http://www.cplusplus.com/reference/iostream/ifstream/ Tutorial from CPlusPlus.com]


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • fstream — C++ Standard Library fstream iomanip ios iostream sstream string …   Wikipedia

  • Data file — A data file is a computer file which stores data to use by a computer application or system. It generally does not refer to files that contain instructions or code to be executed (typically called program files), or to files which define the… …   Wikipedia

  • Fstream — fstream.h is a standard C++ library that handles reading and writing to files either in text or in binary formats. It is an object oriented alternative to C s FILE from the C standard library. fstream is the result of a multiple inheritance with… …   Wikipedia

  • C++ — Desarrollador(es) Bjarne Stroustrup, Bell Labs Información general …   Wikipedia Español

  • C++ — У этого термина существуют и другие значения, см. C. См. также: Си (язык программирования) C++ Семантика: мультипарадигмальный: объектно ориентированное, обобщённое, процедурное, метапрограммирование Тип исполнения: компилируемый Появился в …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”