can i use file input to set array sizes in headers?

This is a discussion on can i use file input to set array sizes in headers? within the C++ Programming forums, part of the General Programming Boards category; I need to set the size of some arrays in the header file. Is it possible. The thing is that ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    8

    can i use file input to set array sizes in headers?

    I need to set the size of some arrays in the header file. Is it possible. The thing is that i'm programming SystemC, which is C++ with a twist, and i don't really know that much about C++ and headers.

  2. #2
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    What do you mean??

    to set the size of an array within a header file???

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    If the arrays in the header files are staticly declared arrays, such as:

    int array[10];

    Then you can't set the size at run-time. However, if the arrays are just pointers then you can easily do it with dynamic memory allocation:

    // Header
    int *array;

    // Main
    cin>>size;
    array = new int[size];

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

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