By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Why are vectors and strings better than arrays?

P: 17
I've got many differences between vectors/strings and arrays but I need more details. I guess I don't really understand it enough to do this but this is what I've concluded so far;

An array is a collection of data storage locations, holding the same type of data and can be individually referenced by adding an index to a unique identifier.

They can be declared by writing the type, the array name and then the number of elements.

A vector contains sequences and orders elements following a strict linear sequence.

A string is a special type of container which is specifically designed to operate with a sequence of characters.

Unlike arrays, vectors and strings can handle storage automatically and can easily be resized.

They also have a richer interface which allows complex functionality to be implemented easily.

Vectors and Strings provide a better platform for creating safe components and are compatible with C's memory model.

They also adopt optimisation from modern standard library implementations.

I feel like some of my information is confused and that some of it might not make sense. But if anyone could assess what I have written and give me more detail so I am able to understand it more, that would be very useful!
Dec 6 '10 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
First: A vector is an array.
Second: A string is an array.

So, you can just create an array and write all of the code to manage the array and keep it from overflowing, resize it, add and remove elements, etc and do this for every array you create. OR you can use the vector and string whichh has this done for you and done in the same way each time AND everyone else already knows how to use the code.

vector is a complete replacement for an array and the C++ spec requires vector be implemented as an array.

string is a complete replacement for C-style strings and all of the C library string functions.
Dec 6 '10 #2

100+
P: 207
I read a cool quote about the STL a while back which I think is relevant to the question at hand.

"Those who don't know the STL are doomed to repeat it, badly."
Dec 6 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.