I’m coding in C++ and I’m in need for a dynamic data storage, like ArrayList in C# or Java.
Can anyone help me with that? I’m not sure what to use.
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are looking for
std::vector. You can read here about it (scroll down on that page to view a description of its functions).Vectors have constant-time lookup. Insertion/removal is fast at the end of a vector, but (as the link I posted explains in more detail) is slower otherwise. Additionally, vectors have to be resized as you store additional data in them, so it is worth looking into
reserve(this is like ArrayLists’ensureCapacity). Note that this resizing is automatic –reserveis there only for performance reasons.