some code in cplusplus.com