C++: Difference between revisions

320 bytes added ,  2 January 2020
Line 280: Line 280:
===Sequences===
===Sequences===
====std::vector====
====std::vector====
[https://en.cppreference.com/w/cpp/container/vector Reference]
[https://en.cppreference.com/w/cpp/container/vector Reference]<br>
Use vector for almost everything...
Use vector for almost everything...<br>
It is an ArrayList.
It is an ArrayList.<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 297: Line 299:
my_vec.empty();
my_vec.empty();


// Equivalent to my_vec[0];
// Undefined on empty vectors
my_vec.front();


 
// Equivalent to my_vec[my_vec.size()-1];
// Undefined on empty vectors
my_vec.back();
</syntaxhighlight>
</syntaxhighlight>