C++: Difference between revisions
(→STL) |
(→Arrays) |
||
Line 22: | Line 22: | ||
[https://shendrick.net/Coding%20Tips/2015/03/15/cpparrayvsvector.html array vs vector] | [https://shendrick.net/Coding%20Tips/2015/03/15/cpparrayvsvector.html array vs vector] | ||
If you need a static sized array, you can use <code>std::array</code>.<br> | If you need a static sized array, you can use <code>std::array</code> in the <code>array</code> header.<br> | ||
This wrapper around C-style arrays gives us size information and allows the array to be passed around while keeping the array on the stack unlike <code>std::vector</code> | This wrapper around C-style arrays gives us size information and allows the array to be passed around while keeping the array on the stack unlike <code>std::vector</code> | ||
If you want to allocate a static array on the heap, you can do so as follows: | If you want to allocate a static array on the heap, you can do so as follows: | ||
Line 28: | Line 28: | ||
auto my_arr = std::make_shared<std::array<char,64>>(); | auto my_arr = std::make_shared<std::array<char,64>>(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Strings=== | ===Strings=== | ||
====String Interpolation==== | ====String Interpolation==== |