Dynamic data in C ++

I am coding in C ++, and I need a dynamic data store like ArrayList in C # or Java.

Can anyone help me with this? I'm not sure what to use. Thanks!

+7
c ++
source share
7 answers

You are looking for std::vector . You can read it here (scroll down the page to see a description of its functions).

Vectors have a constant time search. Insertion / deletion is quick at the end of the vector, but (since the link I posted is explained in more detail) otherwise it’s slower. In addition, vectors must be changed when additional data is stored in them, so it’s worth looking at reserve (this is similar to ArrayLists' ensureCapacity ). Please note that this resizing is automatic - reserve exists only for performance reasons.

+8
source share

std :: vector is what you are looking for.

+11
source share

std::vector is your friend, here is a tutorial.

+4
source share

or std::list , for that matter ...

+1
source share

If you are really just a beginner, you should start with the basics: arrays .

Once you understand what is happening under it, you should go to STL and containers (like vector ), as everyone else suggests.

0
source share

There are two options that appear immediately.

First, use std :: vector. A vector works basically the same as an array (except for the syntax for declaring and calling) on ​​the surface. The 2 things you want to know about vectors is that you can call a function that will increase the size of your vector (add indexes at the end). Another thing is that to create a two-dimensional vector you will need to declare a vector of vectors. It also allows you to have more than 2 values.

Another thing you can use is std :: list. This is just a linked list into which you can insert and delete items.

0
source share

Both of them are undoubtedly mentioned in the list of books, but now it seems that you need one (or both) of the following:

C ++ Standard Library by Nicolai Josuttis.
STL Study Guide and Reference Guide, 2 nd ed. , Musser, Saini and Derge

0
source share

All Articles