C++: Difference between revisions

259 bytes added ,  23 October 2019
no edit summary
No edit summary
Line 17: Line 17:
[https://en.cppreference.com/w/cpp/language/lambda Reference]
[https://en.cppreference.com/w/cpp/language/lambda Reference]


===Arrays===
 
====Casting====
[https://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-const-cast-and-reinterpret-cast-be-used Types of casts]
C++ has several types of casts.
These are the main ones you should use.
* <code>static_cast</code>
* <code>dynamic_cast</code>
If you're casting between things but do not want to change the bit-pattern (e.g. binary data or pointers), you can also use <code>reinterpret_cast</code>.
 
===Array===
<code>#include <array></code><br>
In C++, you can use <code>std::vector</code> which gives you a resizable array.  
In C++, you can use <code>std::vector</code> which gives you a resizable array.  
This will allocate an array in the heap.<br>
This will allocate an array in the heap.<br>
Line 29: Line 39:
</syntaxhighlight>
</syntaxhighlight>


===Strings===
===String===
<code>#include <string></code><br>
====String Interpolation====
====String Interpolation====
[https://stackoverflow.com/questions/10410023/string-format-alternative-in-c Reference]
[https://stackoverflow.com/questions/10410023/string-format-alternative-in-c Reference]
Line 48: Line 59:
</syntaxhighlight>
</syntaxhighlight>
===Filesystem===
===Filesystem===
<code>#include <fstream></code><br>
====Reading and Writing====
====Reading and Writing====
Reading and writing is done using <code>fstream</code>.<br>
Reading and writing is done using <code>fstream</code>.<br>
Line 92: Line 104:


===Regular Expressions===
===Regular Expressions===
<code>#include <regex></code><br>
[https://en.cppreference.com/w/cpp/regex Reference]
[https://en.cppreference.com/w/cpp/regex Reference]
<!--
<!--
Line 106: Line 119:


===Thread===
===Thread===
<code>#include <thread></code><br>
==== Sleep ====
==== Sleep ====
<syntaxhighlight lang="C++">
<syntaxhighlight lang="C++">
Line 114: Line 128:


===Memory===
===Memory===
<code>#include <memory></code><br>
====Smart Pointers====
====Smart Pointers====
[https://www.geeksforgeeks.org/auto_ptr-unique_ptr-shared_ptr-weak_ptr-2/ Smart Pointers]<br>
[https://www.geeksforgeeks.org/auto_ptr-unique_ptr-shared_ptr-weak_ptr-2/ Smart Pointers]<br>
Line 180: Line 195:
</syntaxhighlight>
</syntaxhighlight>


===Casting===
===Limits===
[https://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-const-cast-and-reinterpret-cast-be-used Types of casts]
<code>#include <limits></code><br>
C++ has several types of casts.
These are the main ones you should use.
* <code>static_cast</code>
* <code>dynamic_cast</code>
If you're casting between things but do not want to change the bit-pattern (e.g. binary data or pointers), you can also use <code>reinterpret_cast</code>.


==Programming Styles==
==Programming Styles==