You can check here to get a feel for how to use ofstream. I believe you should be able to use seekp to set the position of the file pointer then write to write there.

There are examples there to help you out as well.

I hope I was of help,

cs_student.