Here is a short program which reads from a file named "data.dat". To access the file we have to create an object of type ifstream. We have called this object ClientFile. Now we can use the > > operator which we recall from cin. In cin this operator reads from the keyboard, here we are using the same operator to read from our object ClientFile which represents the file "data.dat".
A file must be closed when you are finished reading/writing to it.
This will be done automatically when the program exits, but you can do
it earlier if you need to by using the command
ClientFile.close();
This may be usefull if you finish with a file before the program exits.
In fact, as long as you keep the file open for writing, other programs
running at the same time
will not be able to open the file for writing. So you may need to close your
file when you expect multiple programs to be running. In general, it is just
cleaner to close files when you are done with them.