I'm currently seeing a lot of questions which are tagged C++ and are about handling arrays.
There even are questions which ask about methods/features for arrays which a std::vector
would provide without any magic.
So I'm wondering why so much developers are chosing arrays over std::vector
in C++?
In general, I strongly prefer using a vector over an array for non-trivial work; however, there are some advantages of arrays:
Because C++03 has no vector literals. Using arrays can sometime produce more succinct code.
Compared to array initialization:
char arr[4] = {'A', 'B', 'C', 'D'};
vector initialization can look somewhat verbose
std::vector<char> v;
v.push_back('A');
v.push_back('B');
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With