I know how to write basic stuff to a file but I'm having a problem.

In my main function a .txt file is opened up to write data to. The main function creates some objects that are output by using a print function.
Code:
object.print();
The problem that I'm having is that I can't figure out a way to write the data to the same file. The way the program is going to work is the file is always going to be the same name and I can't pass that name as a variable. So I tried just opening up that file in the object member function print's code and appending data to it but that did not work. What's a good way to go about doing this?