Vectors v/s arrays

Jan 3, 2013 at 9:24am
Can any one explain me the difference between the vectors and arrays, like how to access and store the values in them.
Jan 3, 2013 at 4:53pm
For arrays, any basic C or C++ tutorial should cover what you need.

For vectors, look at the reference material on this very site, e.g.

http://www.cplusplus.com/reference/vector/
Jan 3, 2013 at 5:33pm
You can access and store values the same way in both containers. Just std::vector gives you more options to do so, is much safer and dynamically sized (can store an unspecified, growing number of objects).
Jan 4, 2013 at 12:39am
closed account (zb0S216C)
As ResidentBiscuit said, accessing a "std::vector" and an array is identical when the sub-script operator is used. Accessing a "std::vector" and an array with the sub-script operator never explicitly throw exceptions unless the OS believes you're accessing unowned memory.

Microsoft's & GNU's implementation of "std::vector::operator[]( )" never throw exceptions, nor do they check if the index is out-of-range.

Wazzak
Jan 7, 2013 at 6:36am
thank you all
Jan 7, 2013 at 1:09pm
Framework wrote:
Microsoft's & GNU's implementation of "std::vector::operator[]( )" never throw exceptions, nor do they check if the index is out-of-range.

You can make GCC check this by defining the the macro _GLIBCXX_DEBUG when compiling your program. It will print an error message and terminate the program.
Jan 7, 2013 at 1:25pm
> Microsoft's & GNU's implementation of "std::vector::operator[]( )" never throw exceptions,
> nor do they check if the index is out-of-range.

std::vectir<>::at() would become redundant if std::vecto<>r::operator[]( ) also provided for bounds-checked access.
Both std::vector<>, and std::deque<> leave that decision to the programmer who uses the container.
Topic archived. No new replies allowed.