Use std::endl constant instead of "\n" string
Print error on std::cerr instead of std::cout
Return a non-0 code on errors
Another pass of outputs end lines printing