fstream (short for "FileStream" ) is a header file from the C ++ standard library , including a set of classes, methods and functions that provide an interface for reading / writing data from / to a file . Objects called streams are used to manipulate file data.
The functions included in this file allow you to read from files both byte-wise and in blocks, and write in the same way. The kit includes all the necessary functions to control the sequence of access to file data, as well as many auxiliary functions.
Public Functions
These are the root functions of the library, not included in any of the main classes. They are used quite often and can be applied to all stream objects in each of the classes.
rdbuf. Allfstreamobjects can be associated with thefilebuffile buffer object. To map an object of classfstreamto an object of a buffer, use therdbuffunction (without arguments). A buffer object provides much more control over data in a file than the standard functions offstreamsubclasses.
open(). Using this method, you can open the specified file by matching it with one of the stream objects [1] . Depending on the arguments passed, the file can be opened for reading, for writing (either for full or for adding data), as a binary , or as a text file.
is_open(). A function that determines whether a file is currently open to which a specific stream object is mapped. Returns a boolean value. It is mainly used to prevent access errors when trying to open an existing file. No arguments.
close(). The function closes the file, that is, stops access to it, thus freeing it for other functions or programs.
Base classes
ios_base | InputOutputStream_Base , the base class of the entire stream class hierarchy. It contains common functions, types and classes, mainly representing flags (indicators). These flags are used by fstream subclass functions and can be defined using ios_base functions. |
ios | "InputOutputStream" , the main subclass, together with ios_base , which defines all other subclasses of the stream library. Contains flag functions for formatting and error handling, as well as some functions inherited from ios_base . |
ifstream | "InputFileStream" , organizes the reading of data from a file. A class whose functions are used to read files. |
ofstream | "OutputFileStream" , organizes the writing of data to a file. The class used to write data to a file. |
Links
- fstream at cplusplus.com