not in a stand alone function. When you hit return, it stops. It may return a value that alerts the user to do something, or it may throw an exception (see exception handling in c++) that the user may choose to do something, but you can't force it.
you can force it with a class / functor. I don't know if these are still popular, but its a class that behaves like a function and could be rigged to call the destructor or something...
you can also wrap the pointer or stream in a microclass that self destructs cleanly when out of scope, and the function can remain as it was...