Refactoring based on code review

Code review at http://codereview.stackexchange.com/q/33689/45 made some suggestions about how code could be more idiomatic. The biggest performance improvements came from replacing the C++ input and output streams with C-style file pointers.