C++ tutorial code from http://arachnoid.com/cpptutor