Syntax highlighting for different programming languages [duplicate]

In my paper I want to include some source codes with colored sytax. For syntax highlighting I use the listings package:

\lstset{frame=tb,
language={[Visual]Basic},
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true
tabsize=3
}


And then in the document:

\begin{lstlisting}
'test
\end{lstlisting}


This works for one language (Visual Basic in the example above). But now I also want to include some C code. How can I achieve this?

-

marked as duplicate by diabonas, Werner, mafp, Claudio Fiandrino, Torbjørn T.Apr 2 '13 at 14:38

–  Mike Renfro Apr 2 '13 at 13:41
Welcome to TeX.sx! –  hpesoj626 Apr 2 '13 at 13:48
Thanks Mike, that was just what I needed. –  alxppp Apr 2 '13 at 13:56

You can also define your own language dependent environments:

\documentclass{article}
\usepackage{listings}
\lstnewenvironment{C}
{\lstset{language=C,frame=lines}}
{}
\lstnewenvironment{CPP}
{\lstset{language=C++,basicstyle=\ttfamily\small,frame=none}}
{}
\begin{document}

\begin{C}
#include<stdio.h>
main() {
printf("Hello World");
}
\end{C}

\begin{CPP}
#include <iostream.h>
main() {
cout << "Hello World!";
return 0;
}
\end{CPP}
\end{document}


-