% 必须加下列两句
\documentclass[compress,red]{beamer}
\mode<presentation>\begin{document}
% -----------------定义你的代码部分[BEGIN]--------------------%
% \mycode指你的代码名,方便后面直接使用
% emph指定你要强调的关键字
% emphstyle指定强调使用什么颜色
\defverbatim[colored]\mycode{%\begin{lstlisting}[frame=single, emph={cout,cin}, emphstyle={\color{blue}}]
cin >> a;
}
%-----------------定义你的代码部分[END]--------------------%
\begin{frame}
% 直接调用
\mycode