Mortennobel - Cpp-Cheatsheet - Modern C++ Cheatsheet
Mortennobel - Cpp-Cheatsheet - Modern C++ Cheatsheet
2k
stars
549
forks
Star
Watch
master
View code
Preprocessor
/* Multi-line comment */
#define X \
https://github.com/mortennobel/cpp-cheatsheet 1/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
Literals
'\n', '\\', '\'', '\"' // Newline, backslash, single quote, double quote
Declarations
unsigned long x =
std::string s = R"(Hello
enum weekend {SAT,SUN}; // weekend is a type with values SAT and SUN
enum class Color {Red,Blue};// Color is a strict type with values Red and Blue
https://github.com/mortennobel/cpp-cheatsheet 2/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
const int* const p=a; // Both p and its contents are constant
int8_t,uint8_t,int16_t,
uint16_t,int32_t,uint32_t,
auto& s = singleton::instance();
STORAGE Classes
Statements
; // Empty statement
https://github.com/mortennobel/cpp-cheatsheet 3/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
try { a; }
Functions
int f(int x, int y); // f is a function taking 2 ints and returning int
Function parameters and return values may be of any type. A function must either be
declared or defined before
it is used. It may be declared first and defined later. Every
program consists of a set of a set of global variable
declarations and a set of function
definitions (possibly in separate files), one of which must be:
Functions with different parameters may have the same name (overloading). Operators
except :: . .* ?: may be overloaded.
Precedence order is not affected. New operators
may not be created.
Expressions
Operators are grouped by precedence, highest first. Unary operators and assignment
evaluate right to left. All
others are left to right. Precedence does not affect order of
evaluation, which is undefined. There are no run time
checks for arrays out of bounds,
invalid pointers, etc.
https://github.com/mortennobel/cpp-cheatsheet 4/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
typeid(x) // Type of x
~x // Bitwise complement of x
-x // Unary minus
&x // Address of x
x * y // Multiply
x + y // Add, or \&x[y]
x ^ y // Bitwise exclusive or (3 ^ 6 is 5)
x | y // Bitwise or (3 | 6 is 7)
https://github.com/mortennobel/cpp-cheatsheet 5/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
Classes
};
public:
https://github.com/mortennobel/cpp-cheatsheet 6/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
// Multiple inheritance
All classes have a default copy constructor, assignment operator, and destructor, which
perform the
corresponding operations on each data member and each base class as shown
above. There is also a default no-argument
constructor (required to create arrays) if the
class has no constructors. Constructors, assignment, and
destructors do not inherit.
Templates
// Definition of constructor
Namespaces
if (y.get() != x.get()) {
https://github.com/mortennobel/cpp-cheatsheet 7/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
unique_ptr<int> q;
if (z == nullptr){
shared_ptr<B> r;
https://github.com/mortennobel/cpp-cheatsheet 8/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
c = cin.get(); // c = getchar();
s1[0]; // 'h'
a.back()=4; // a[10]=4;
https://github.com/mortennobel/cpp-cheatsheet 9/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
a.front(); // a[0];
for (int& p : a)
utility (pair)
a.first; // "hello"
a.second; // 3
a.size(); // 1
https://github.com/mortennobel/cpp-cheatsheet 10/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
a.size(); // 1
s.erase(123);
s.erase(123);
https://github.com/mortennobel/cpp-cheatsheet 11/13
06/07/2022 10:09 mortennobel/cpp-cheatsheet: Modern C++ Cheatsheet
high_resolution_clock::now();
high_resolution_clock::now();
unsigned c =
};
= nullptr;
README.md
auto pingPongFn = // thread body (lambda). Print someone else's mess
[&](const char* mes){
while (true){
do {
});
sharedMes = mes;
};
sharedMes = "ping";
[&](int i){
if (i <= 1){
return 1;
return fib(i-1)
+ fib(i-2);
};
Releases
No releases published
Packages
No packages published
Contributors 3
mortennobel
Morten Nobel-Jørgensen
Khalilw1
Ait Brahim Mohammed Khalil
Naereen
Lilian Besson
Environments 1
github-pages
Active
Languages
C++ 100.0%
https://github.com/mortennobel/cpp-cheatsheet 13/13