TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I write a program by DevC++ compiler and save it by .cpp format, and want to paste the code in my editor, Do I have to paste all the code each time? Is there a way to include the file instead of copying and pasting the code over and over? I suppose there should be a way because for a program of about 100 lines the including the file is more convenient.

share|improve this question
You are probably looking for lstinputlisting. Just do a quick search here on the site: tex.stackexchange.com/search?q=lstinputlisting – topskip Jan 31 '12 at 10:50
up vote 13 down vote accepted

Normally this is done using the listings package. It provides a lstlisting environment for verbatim code and also a \lstinputlisting[<options,...>]{<file name>} to include an external file verbatim. As options you can select language=C++ to get specific syntax highlighting. I also usually use basicstyle=\ttfamily. See the listings package manual for more details.

share|improve this answer
I actually use this package , all I didn't know was how include my c++ file instead of pasting the code each time . – Negin Jan 31 '12 at 12:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.