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.
[Tex/LaTex] Including a text file in LaTeX
inputsourcecodeverbatim
Best Answer
Normally this is done using the
listings
package. It provides alstlisting
environment for verbatim code and also a\lstinputlisting[<options,...>]{<file name>}
to include an external file verbatim. As options you can selectlanguage=C++
to get specific syntax highlighting. I also usually usebasicstyle=\ttfamily
. See thelistings
package manual for more details.