Array Question

This is a discussion on Array Question within the C++ Programming forums, part of the General Programming Boards category; I want to get this out of the way. It may sound stupid, but I always end up doing it ...

  1. #1
    Satan valar_king's Avatar
    Join Date
    Aug 2001
    Posts
    288

    Array Question

    I want to get this out of the way. It may sound stupid, but I always end up doing it wrong and causing all sorts of problems.

    How do I make an array with an unlimited amount of elements.

    Thanks
    -Save the whales. Collect the whole set.

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    You can't. To create a static or even dynamic array you have to specify the size.
    If you want to have a container that can hold an "unlimited" (which of course is not possible because you can always run out of memory ) number of elements, you can use a linked list or other such data structure.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,675
    Use one of the provided STL containers, probably a vector would be best for you. For example...
    Code:
    #include <vector>
    ...
    vector<int> v1;  // Create a vector to hold ints
    ...
    // Now just keep pushing ints onto the vector to your heart's content.
    // It will keep growing and growing...
    v1.push_back(1);
    v1.push_back(14);
    ...
    v1.push_back(-6);
    I used to be an adventurer like you... then I took an arrow to the knee.

  4. #4
    Satan valar_king's Avatar
    Join Date
    Aug 2001
    Posts
    288
    Originally posted by hk_mp5kpdw
    Use one of the provided STL containers, probably a vector would be best for you. For example...
    Code:
    #include <vector>
    ...
    vector<int> v1;  // Create a vector to hold ints
    ...
    // Now just keep pushing ints onto the vector to your heart's content.
    // It will keep growing and growing...
    v1.push_back(1);
    v1.push_back(14);
    ...
    v1.push_back(-6);
    That's nice, but what's the liscence info on that.
    Do big game developers use it?
    -Save the whales. Collect the whole set.

  5. #5
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    It's part of the STL.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 06:07 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 05:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21