replace printf with cout, per Michael's request