hi...i ve been used to vectors stl
but is it nececssary to mention the size of the vector in the declararion...
can i not leave it unspecified...dynamically increasing as and wen i push items to it....
hi...i ve been used to vectors stl
but is it nececssary to mention the size of the vector in the declararion...
can i not leave it unspecified...dynamically increasing as and wen i push items to it....
Yes, you can.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
No.Originally Posted by dpp
You can indeed increase the size of a std::vector at run time with push_back and other member functions.Originally Posted by dpp
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
thanks...then how will my declaration be...with an example plz
Perhaps post what you have tried? You'll declare an empty vector like any other object with default constructor.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
simple eg:
vector<long long int>g(1000);
i get error if i use g()
It should be:Originally Posted by dpp
This declares a function named g that takes no arguments and returns a vector:Code:vector<long long int> g;
Note that at the moment long long int is not a standard C++ built-in type.Code:vector<long long int> g();
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
thanks...but i dont get it right with normal push_back function....
anythng else needed
That's too bad, I use it and it works.Originally Posted by dpp
Yes.Originally Posted by dpp
(If you don't get what I am hinting at: post what you tried and state how exactly does it not work.)
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
it works well normally for simple eg....
when i include in my program i get an error....
thanks...
i need to check with it
ya ok...say for eg:
i get runtime errorCode:#include<iostream> #include<vector> using namespace std; int main() { int i,j=0; //vector<<int> g; vector < vector<long long int> > g; while(1) { j++; cin>>i; if(i==-1)break; g[j].push_back(i); } return(0); }
g is empty so you cannot insert into g[0].
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
ya that is the reasion i used g(maxvalue) in declaration...
but how can i leave it unbounded
i want it to be unspecified bound and increasing as and when i push elements....
can i do it...
if so how