It's known to everyone of us that we should prefer string
class in C++
for all string applications due to the many special functions they perform & their ability to grow & reduce dynamically. What string
is for characters
, vector
is for other data types & classes because it shows great performance.
However is there any situation where we would need to prefer vector<char>
(which I see seldom) over string
?
I'd use vector<char>
only if I explicitly intent to store an array of char values, which is not a string. E.g. if for some reason I'd collect all the characters used somewhere in a specific text, the result might be a vector<char>
.
To be clear: it is all about expressing the intent.
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