Declaring global variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dn6326
    New Member
    • Sep 2007
    • 6

    Declaring global variables

    hi, essentially, my program needs to store an array of lists so that in main() it can have 2 run modes from the command line.

    i.e. i can run the program with
    Code:
    ./matrix load filename
    to load a matrix into my array of lists
    then use
    Code:
    ./matrix find 1 3
    to do something to the matrix I have just made (which is an array of lists)

    i was going to create a global variable which was an array of lists but i need to know the size of it to declare it that way and I only know the size by running ./matrix load filename

    Any ideas on how to go about this or other ways around it?

    Cheers, Dan

    P.S Dont ask why I am using an array of lists (but its pretty important that i do it that way)
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by dn6326
    hi, essentially, my program needs to store an array of lists so that in main() it can have 2 run modes from the command line.

    i.e. i can run the program with
    Code:
    ./matrix load filename
    to load a matrix into my array of lists
    then use
    Code:
    ./matrix find 1 3
    to do something to the matrix I have just made (which is an array of lists)

    i was going to create a global variable which was an array of lists but i need to know the size of it to declare it that way and I only know the size by running ./matrix load filename

    Any ideas on how to go about this or other ways around it?

    Cheers, Dan

    P.S Dont ask why I am using an array of lists (but its pretty important that i do it that way)

    Hi,
    i assume that you are asking the way how to declare the list array.
    [code=cpp]
    typedef list<int> Int_List;
    Int_List *list_arr;
    [/code]
    The above piece helps you to acjieve the same

    Thanks
    Raghuram

    Comment

    • Laharl
      Recognized Expert Contributor
      • Sep 2007
      • 849

      #3
      An array of lists would be a list<int>[], or for easier use, a vector<list<int >.

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Originally posted by Laharl
        An array of lists would be a list<int>[], or for easier use, a vector<list<int >.

        What you say is right.
        Since he has tole that he has to use array and the sie will be determined at run-time i went for this approach

        Raghuram

        Comment

        Working...