please, what contains the fstream variable? A can find many tutorials on fstream, but no ona actually says what is the fstream file; declaration in the beginning. Thanks.
please, what contains the fstream variable? A can find many tutorials on fstream, but
Share
The fstream class is an object that handles file input and output. It is mostly equivalent to both an ifstream and ostream object in one, in that you can use it for both input and output. This tiny demonstration will create a file and write data to it.
What is cool about fstream objects is that you can use them to read and write binary memory images to files (to protect your file’s data from editing) and set various flags to control the way in which the fstream processes input and output. For example:
This fstream is an output stream that clears fout.txt’s data and writes in binary.
This fstream is an output stream that does not clear fout.txt’s data, but appends to the end of it instead, and writes in binary.
If I remember right, foutTwo will crash if fout.txt does not exist, while foutOne will not. You can (and should ALWAYS) check if the fstream loaded correctly immediately after opening a file like so: