473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why are vectors and strings better than arrays?

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
2 2794
weaknessforcats
9,208 Expert Mod 8TB
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
hype261
207 100+
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

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

Similar topics

4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
6
by: Bryan Dickerson | last post by:
I have a string that is delimited, e.g. "SOD;NAME;ADDRESS1;ADDRESS2;PHONE;CITY;STATE;ZIP;EOD", that I need to strip off the "SOD;" at the beginning and the ";EOD" at the end. I am well familiar...
3
by: Keo932 | last post by:
Im having trouble with the last part of an assignment of storing a user defined string into a one dimensional array. If anyone can help it would be much appreiated. Here's what it requests: Prompts...
8
by: LinuxDuud | last post by:
Hi, First, Sorry if the title was bad, I really didn't know how to describe this. So, What I need to do is something like this: char somevariable; // The tricky part. I don't know how to define...
6
by: Tim Streater | last post by:
Safari and FF seem to allow this: var wiggy = "ABCD"; ch = wiggy; // ch will contain the character 'C' however my JS book seems to insist that I do this: ch = wiggy.charAt(2);
45
by: Nkhosinathie | last post by:
hello everyone,i'm writing this program to enter a name and marks of a student and after that a message should pop out to say whether the student has passed or supplementing or repeating next year....
6
m6s
by: m6s | last post by:
1. After hours of researching, I used these snippets : void Object::TokenizeLines(const string& str, vector<string>& tokens, const string& delimiters) // Skip delimiters at beginning....
5
by: Jim | last post by:
Hi There. I have to create a function that will take a sentence and breakout the words and save them into an array. For some reason, I can't get it working. I keep getting a segmentation fault...
8
by: darren | last post by:
Hi everybody, have a quick look at this code: ===== ===== int main(void) { string msg; makeString(msg); cout << "back in main, result = " << msg << endl;
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.