Vector in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JSagar
    New Member
    • Jul 2007
    • 2

    Vector in C++

    Hello Expert!

    I need help abt Vector in C++, I want to used 2 dimension Vector But the Problem is i need Specify Size of Vector , But I want Size Should be Dynamic ,

    i Can used Vector as Link list type like Whenever data Come i push_back data .

    Regards
    Sagar Jagtap
    Pune.
  • Girish Kanakagiri
    New Member
    • May 2007
    • 93

    #2
    Originally posted by JSagar
    Hello Expert!

    I need help abt Vector in C++, I want to used 2 dimension Vector But the Problem is i need Specify Size of Vector , But I want Size Should be Dynamic ,

    i Can used Vector as Link list type like Whenever data Come i push_back data .

    Regards
    Sagar Jagtap
    Pune.
    Vector of STL is making its size Dynamic in nature. You need not worry about its size. Just make use of functions available. It can automaticall grow as well
    as Shrink depending on the elements present in the vector.

    Regards,
    Girish.

    Comment

    • Meetee
      Recognized Expert Contributor
      • Dec 2006
      • 928

      #3
      Originally posted by JSagar
      Hello Expert!

      I need help abt Vector in C++, I want to used 2 dimension Vector But the Problem is i need Specify Size of Vector , But I want Size Should be Dynamic ,

      i Can used Vector as Link list type like Whenever data Come i push_back data .

      Regards
      Sagar Jagtap
      Pune.
      Hi Sagar,

      You can do something like this:
      Code:
      vector< vector<int> > Y;
      then in Constructor
      myClass::myClass (int x, int y)
       : Y (x, vector<int>(y)) {x=a;y=b; //a and b are some values)}
      fun()
      {
       for (int i=1; i <x;i++)
       for (int j=0; j<y; j++)
       {
       Y[i][j] = value;
       }
      }
      May this helps,
      Regards

      Comment

      Working...