Problem re-compiling code

If I have a c++ file, and then run it and if it doesn’t work, I then have to remove the file rm filename and recompile. It is not a huge inconvenience but I would rather not have to do that. Do any of you know how to overwrite a file when compiling to it?

Are you sure you have to delete the whole thing just to recompile? I think if you just run a g++, it should overwrite the existing exe file if there is one.