My Proffessor did the following code. What exactly is this code doing? from my opinion, it is opening the file, but I thought to open an output file you do fout.open("closedata.dat)
In your code, you create an ofstream object, then you open the file. Your professor is creating the object and opening the file at the same time. This is done using a constructor.
A constructor is the function which is called to initialize the object. If you don't specify a constructor, then the default constructor is used. ofstream objects have two constructors described on this page: http://www.cplusplus.com/reference/fstream/ofstream/ofstream/
The first is the default constructor you used. This one does not take any parameters and the fout is not associated with any file yet. The second is the constructor your professor used:
It's described as:
initialization constructor
Constructs an ofstream object, initially associated with the file identified by its first argument (filename), open with the mode specified by mode.
Internally, its ostream base constructor is passed a pointer to a newly constructed filebuf object (the internal file stream buffer). Then, filebuf::open is called with filename and mode as arguments.
If the file cannot be opened, the stream's failbit flag is set.