Reply embedded... > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of > Robert Ryan > Sent: Friday, February 02, 2007 10:20 AM > To: [email protected] > Subject: Re: [c-prog] what is a vector ? > > i will start over, thanks: > > for (int i=0; i<num.length; i++) {
What is the type of 'num'? 'num.length' doesn't make sense. > total += num[i]; >From this line alone, you can't really tell the difference. A std::vector is designed such that its element can be accessed like an array, using array syntax. > } > cout << "The total is "<< total << endl; > } > > how is a vector diff from an array: An array is fixed size collection of the same type. In C, array with runtime-determined size can only be accomplished using dynamic allocation (malloc() and friends). You can also use the allocation functions to expand and shrink the array size, but you have to do all the necessary bookkeeping tasks yourself, in your code. The C++ std::vector does all these chores for you. Shyan
