Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to make a list with a dynamic length?  (Read 978 times)

0 Members and 1 Guest are viewing this topic.

bobojoeho

  • Newbie
  • *
  • Posts: 11
    • View Profile
How to make a list with a dynamic length?
« on: March 15, 2024, 12:11:23 am »
So I want to make a list that I can change the length of during my program.

Making an array requires me to set its length whenever I create the array, and that length is permanent.

Any ways to store a list of numbers, such that I can increase the length of the list or decrease it whenever I want?

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: How to make a list with a dynamic length?
« Reply #1 on: March 15, 2024, 06:02:29 am »
std::vector is the class you want. It's a dynamic resizable array as part of the C++ standard.

bobojoeho

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to make a list with a dynamic length?
« Reply #2 on: March 15, 2024, 07:17:37 pm »
ok thanks

i am new to c++ so i am just learning about arrays and stuff

 

anything