The obvious way to print out the value of a variable when you change it is to configure a debugger to do that. That is not a C++ programming solution though.

I suspect the OP has been asked for...