array of variable length

Discussion in 'C++' started by Huub, May 8, 2011.

  1. Huub

    Huub Guest

    Hi,

    I want to create an array, but it's length be specified by console input.
    Is this possible?

    Thanks
     
    Huub, May 8, 2011
    #1
    1. Advertising

  2. Huub

    Marc Guest

    Huub wrote:

    > I want to create an array, but it's length be specified by console input.
    > Is this possible?


    If you mean:
    int tab[variable];
    or
    std::array<int,variable> tab;

    ---> no.

    If you mean:
    int* tab=new int[variable];
    or
    std::vector<int> tab(variable);

    ---> yes.
     
    Marc, May 8, 2011
    #2
    1. Advertising

  3. Huub

    Huub Guest

    On Sun, 08 May 2011 12:53:00 +0000, Marc wrote:

    > Huub wrote:
    >
    >> I want to create an array, but it's length be specified by console
    >> input. Is this possible?

    >
    > If you mean:
    > int tab[variable];
    > or
    > std::array<int,variable> tab;
    >
    > ---> no.
    >
    > If you mean:
    > int* tab=new int[variable];
    > or
    > std::vector<int> tab(variable);
    >
    > ---> yes.


    Thank you.
     
    Huub, May 8, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mitchua
    Replies:
    5
    Views:
    2,752
    Eric J. Roode
    Jul 17, 2003
  2. =?Utf-8?B?SG96aQ==?=
    Replies:
    1
    Views:
    6,972
    Ken Cox [Microsoft MVP]
    Jun 2, 2004
  3. Adam Warner

    Flexible array member + variable length array

    Adam Warner, Feb 3, 2005, in forum: C Programming
    Replies:
    10
    Views:
    803
    S.Tobias
    Feb 10, 2005
  4. Tom
    Replies:
    3
    Views:
    215
    salsablr
    Dec 20, 2004
  5. Tuan  Bui
    Replies:
    14
    Views:
    479
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page