\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Leupi} \pdfinfo{ /Title (c-cheatsheet-inc-c-2011.pdf) /Creator (Cheatography) /Author (Leupi) /Subject (C++ Cheatsheet(inc. C++2011) Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{424242} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{C++ Cheatsheet(inc. C++2011) Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Leupi} via \textcolor{DarkBackground}{\uline{cheatography.com/5907/cs/1197/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Leupi \\ \uline{cheatography.com/leupi} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 18th August, 2013.\\ Updated 13th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.04517 cm} x{3.93183 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Standard Sytemtypes and their range}} \tn % Row 0 \SetRowColor{LightBackground} int8\_t & -128 to 127 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} uint8\_t & 0 to 255 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} int16\_t & -32768 to 32767 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{uint16\_t} & 0 to 65535 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} int32\_t & -2147483648 to 2147483647 \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \seqsplit{uint32\_t} & 0 to 4294967295 \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} int64\_t & -9.2 * 10\textasciicircum{}18\textasciicircum{} to 9.2 * 10\textasciicircum{}18\textasciicircum{} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \seqsplit{uint64\_t} & 0 to 1.8 * 10\textasciicircum{}19\textasciicircum{} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Literals \& Co.}} \tn % Row 0 \SetRowColor{LightBackground} 255 & Integer \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} 0xaf & Hexadecimal Integer \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} 1234.0 & double \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} 234.243f & float \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} true & bool \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} "Hello World" & string/c-string \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} 'a' & char \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Preprocessor}} \tn % Row 0 \SetRowColor{LightBackground} \#include \textless{}LIB\textgreater{} & Includes standard header file LIB \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \#include "Header.h" & Includes Header.h file \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \#define PI 3.14159265359 & Defines Easy Macro \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \#define f(a,b) a+b & More Complex Macro \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \#undef PI & Remove Definition \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} \#ifdef PI & Checks for definition, if true, code will be compiled \tn % Row Count 12 (+ 3) % Row 6 \SetRowColor{LightBackground} \#else & Else part of the above if-statement \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \#endif & Ends the if-statement \tn % Row Count 15 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Nullpointer}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{int* pInt; \newline % Row Count 1 (+ 1) //old, deprecated: \newline % Row Count 2 (+ 1) if(pInt == NULL) \newline % Row Count 3 (+ 1) //new: \newline % Row Count 4 (+ 1) if(pInt == nullptr) \newline % Row Count 5 (+ 1) //still valid: \newline % Row Count 6 (+ 1) if(!pInt)% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.74655 cm} x{4.23045 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Bitwise Operators}} \tn % Row 0 \SetRowColor{LightBackground} \& & Bitwise AND \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} | & Bitwise OR \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textasciicircum{} & Bitwise XOR \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textasciitilde{} & Bitwise NOT \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \textless{}\textless{} & Shift left \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textgreater{}\textgreater{} & Shift right \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Boolean Logic}} \tn % Row 0 \SetRowColor{LightBackground} == & Test of equality \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} != & Test of non-equality \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textless{} & Less than \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textgreater{} & Greater than \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \textless{}= & Less than or equal \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textgreater{}= & Greater than or equal \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} ! & NOT \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \&\& & AND \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} || & OR \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Boolean expressions in C++ are evaluated left-to-right!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Basic Operators}} \tn % Row 0 \SetRowColor{LightBackground} + & addition \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} - & subtraction \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} * & multiplication \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} / & division \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \% & modulo \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} ++var & increase before evaluation \tn % Row Count 7 (+ 2) % Row 6 \SetRowColor{LightBackground} var++ & increase after evaluation \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} condition ? result : alternative; & short form of if-like structure \tn % Row Count 11 (+ 2) % Row 8 \SetRowColor{LightBackground} :: & Scope Operator \tn % Row Count 12 (+ 1) % Row 9 \SetRowColor{white} -\textgreater{} & pointer-to-member \tn % Row Count 13 (+ 1) % Row 10 \SetRowColor{LightBackground} . & Access member \tn % Row Count 14 (+ 1) % Row 11 \SetRowColor{white} \textless{}\textless{} \textgreater{}\textgreater{} & Bitshift(with streams: input/output) \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.64701 cm} x{4.32999 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Pointers: Quick and dirty}} \tn % Row 0 \SetRowColor{LightBackground} \& & Gets RAM adress of Variable(to save into pointer) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} * & Dereferences pointer(returns it´s content) or defines a variable to be a pointer \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} -\textgreater{} & Access pointer class member. same as (*pointer).member() \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} new & Create new object on heap, returns pointer to object \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{delete} & Remove object at the pointer on heap \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Pointers allocate space on heap, normal variables on stack!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{using replaces typedef}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{//typedef is deprecated \newline % Row Count 1 (+ 1) typedef uint32\_t uint32; \newline % Row Count 2 (+ 1) //now: using directive! \newline % Row Count 3 (+ 1) //using identifier = type\_name; \newline % Row Count 4 (+ 1) using uint32 = uint32\_t;% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Auto Datatype}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{//auto is an automatic datatype: \newline % Row Count 1 (+ 1) int x = 4; //equals: \newline % Row Count 2 (+ 1) auto y = 4; \newline % Row Count 3 (+ 1) //works for most cases, esp. STL: \newline % Row Count 4 (+ 1) for(std::vector\textless{}int\textgreater{}::Iterator it = v.begin().....) \newline % Row Count 6 (+ 2) //with auto: \newline % Row Count 7 (+ 1) for(auto it = v.begin; it != v.end(); ++it)% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Compile-time assertion check}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{static assert(bool\_constexpr, string)% Row Count 1 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Multithreading}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{//Thread Creation \& Management: \newline % Row Count 1 (+ 1) void thread\_func(int a) \newline % Row Count 2 (+ 1) \{ \newline % Row Count 3 (+ 1) std::cout \textless{}\textless{} "My Number is: " \textless{}\textless{} a; \newline % Row Count 4 (+ 1) \} \newline % Row Count 5 (+ 1) main() \newline % Row Count 6 (+ 1) \{ \newline % Row Count 7 (+ 1) std::thread t1(thread\_func(1)); \newline % Row Count 8 (+ 1) t1.join(); \newline % Row Count 9 (+ 1) \} \newline % Row Count 10 (+ 1) //Synchronization via: \newline % Row Count 11 (+ 1) std::mutex.lock(); \newline % Row Count 12 (+ 1) std::mutex.unlock();% Row Count 13 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Range based loops}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{//Easy range based loop: \newline % Row Count 1 (+ 1) std::vector\textless{}int\textgreater{} vec = .....; \newline % Row Count 2 (+ 1) for(int i : vec) //foreach i in vec \newline % Row Count 3 (+ 1) //Same with auto: \newline % Row Count 4 (+ 1) const auto vi = ....; \newline % Row Count 5 (+ 1) for(auto i : vi)% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Works with all Containers with begin() and end()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}