How to write "C++" in LaTeX

I've found that the following gives good results:

\def\Cplusplus{C\raisebox{0.5ex}{\tiny\textbf{++}}}

I've been using the code below to typset a nice looking C++ in my Master-Thesis. The code has been copied verbatim from a german forum. You should be able to just copy-paste all the code in a new .tex-document and pick the relevant stuff for you...

\documentclass{article}
\usepackage{relsize}
\usepackage{lipsum}

%c from texinfo.tex
\def\ifmonospace{\ifdim\fontdimen3\font=0pt }

%c C plus plus
\def\C++{%
\ifmonospace%
    C++%
\else%
    C\kern-.1667em\raise.30ex\hbox{\smaller{++}}%
\fi%
\spacefactor1000 }

%c C sharp
\def\Csharp{%
\ifmonospace%
    C\#%
\else%
    C\kern-.1667em\raise.30ex\hbox{\smaller{\#}}%
\fi%
\spacefactor1000 }

\begin{document}
\begin{center}
{\Huge C++ $\rightarrow$ \C++ \& \Huge C\# $\rightarrow$ \Csharp}\\
\bigskip
\ttfamily
{\Huge C++ $\rightarrow$ \C++ \& \Huge C\# $\rightarrow$ \Csharp}\\
\bigskip
\sffamily
{\Huge C++ $\rightarrow$ \C++ \& \Huge C\# $\rightarrow$ \Csharp}
\end{center}
\section{\C++}
\lipsum[1]
\subsection{\Csharp}
\lipsum[1]
\end{document}

The standard solution for cases like this is to use verbatim:

\verb!C++!

You could try and use a typewriter font.

\texttt{C++}

Tags:

Latex