No clue how to do this....
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?
I have a main function:
Code:
ofstream csis;
int main(){
csis.open("csis.dat");
Do Stuff...
cout << stuff; //outputs stuff to the terminal window
csis << stuff; //writes the same stuff to the file
Object fun;
fun.dosomething(x,y);
fun.print(); //this is where the problem comes in
csis.close()
}
The Object member function print looks like this:
Code:
void Object::print(){
cout << something; //outputs something to the terminal window;
csis << something; //I want to somehow write this to the same file/append it to the file
}
Note: I've already overloaded << operator for a different reason and it can't be changed. No parameters can be passed to the print function. The data file will be the same file everytime though. I tried to just make the code open up that same file again and append to it but it only appends at the very end of the program and then it just looks like it dumps a buffer it had filled up.