Jump to content

C++: Difference between revisions

155 bytes added ,  20 October 2023
Line 483: Line 483:


====std::vector====
====std::vector====
[https://en.cppreference.com/w/cpp/container/vector Reference]<br>
<code>#include <vector></code>
Use vector for almost everything...<br>
https://en.cppreference.com/w/cpp/container/vector<br>
It is an ArrayList.<br>
This is a dynamically-allocated resizable array, known as an ArrayList in Java.<br>
Note that <code>vector<bool></code> is not an array of bools.<br>
This has several nuances so you should use <code>vector<char></code> instead.<br>
<syntaxhighlight lang="c++">
<syntaxhighlight lang="c++">
// Basics
// Basics
Line 510: Line 508:
my_vec.back();
my_vec.back();
</syntaxhighlight>
</syntaxhighlight>
Note that [https://en.cppreference.com/w/cpp/container/vector_bool <code>vector<bool></code>] is a special case of bit-packed booleans instead of an array of bools. You should use <code>vector<char></code> instead if your code relies on it being continguous.<br>


====std::span====
====std::span====