I have 2 fstream objects called oldFile and newFile and I want to find the non-Null elements in oldFile and write them into newFile of a destructor. The name of the file would be exactly the same "file.txt" so I am essentially overwriting oldFile with newFile.
~Destructor(){
    T foo;
    fstream newFile;
    oldFile.open(fileName, ios::in | ios::out | ios::binary);
    oldFile.clear();
    while(!oldFile.eof()){
        foo.readFromFile(oldFile);
        if(!foo.isNull()){
            foo.writeToFile(newFile);
        }
    }
}
Where do I go from here? How do I name the newFile object to "file.txt" and make sure that the oldFile object is overwritten? Very basic file I/O, don't need anything too fancy.
