The minted package creates nicely formatted and colorized code listings. It requires that you run pdflatex with the flag -shell-escape.
pdflatex
-shell-escape