The blank line at the end of your code is caused by the newline character at the very end of your embedded listing, i.e. at the end of the line
#include <iostream>
Because \end{lstlisting}
hasn't been detected yet, listings
prints that newline character verbatim. The same phenomenon occurs with the verbatim
environment; see the "side note" in this answer.
That blank line will go away if you remove the newline character in question, by writing
\begin{lstlisting}
#include <iostream>\end{lstlisting}
instead of
\begin{lstlisting}
#include <iostream>
\end{lstlisting}
See section 2 in my code below.
Alternatively, if you load the lstautogobble
package and activate the autogobble
key (which is desirable here, to prevent too much indentation in the output), that extra blank line disappears; see section 3 in my code below.
Also, note that no countermeasure is required for standalone listings, i.e. listings residing in external source files and inserted in your document via the \lstinputlisting
macro. The extra blank line problem only occurs for embedded listings (i.e. listings contained within an lstlisting
environment). See section 4 in my code below.
Finally, regarding the space after the listing, I usually tweak the value of belowskip
globally; in your case, -0.5em
seems appropriate.

\documentclass[a4paper]{scrartcl}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage[latin1]{inputenc}
\usepackage[ngerman,english]{babel}
\usepackage{listings}
\usepackage{lstautogobble}
\lstset
{
language = [Visual]{C++},
keepspaces = true,
tabsize = 2,
xrightmargin = \parindent,
basicstyle = \ttfamily,
frame = single,
framesep = 1mm,
framerule = 0pt,
columns = fullflexible,
belowskip = -0.5em,
backgroundcolor = \color[gray]{0.9},
}
\usepackage{filecontents}
\begin{filecontents*}{sample.c}
#include <iostream>
\end{filecontents*}
\begin{document}
\section{Your listing}
There are two kinds of header files:
\begin{itemize}
\item content
\begin{lstlisting}
#include <iostream>
\end{lstlisting}
\item more content.
\end{itemize}
\section{Your listing without the newline at the end}
There are two kinds of header files:
\begin{itemize}
\item content
\begin{lstlisting}
#include <iostream>\end{lstlisting}
\item more content.
\end{itemize}
\section{Your listing with \texttt{autogobble}}
There are two kinds of header files:
\begin{itemize}
\item content
\begin{lstlisting}[autogobble]
#include <iostream>
\end{lstlisting}
\item more content.
\end{itemize}
\section{Your listing inserted from an external file}
There are two kinds of header files:
\begin{itemize}
\item content
\lstinputlisting{sample.c}
\item more content.
\end{itemize}
\end{document}
`
to mark your inline code as I did in my edit.