The standard way to clean up your process is to register a function with atexit
.
void clean_myfile {
std::remove( "myfile.txt" );
}
int main() {
std::ofstream output("myfile.txt", std::ios::binary | std::ios::trunc);
std::atexit( clean_myfile );
}
This will run if the process is exited gracefully, platform details notwithstanding.