vector

J

john townsley

in c++ (vc6++) if I have a vector conatiner. I simply add items to a vector
and i want to see how many items I now have.
How do I do this because resize,size,capacity doesnt give the number of
items stored in the vector.
 
J

Jonathan Mcdougall

john said:
in c++ (vc6++) if I have a vector conatiner. I simply add items to a vector
and i want to see how many items I now have.
How do I do this because resize,size,capacity doesnt give the number of
items stored in the vector.

std::vector::size() returns the number of items in
the vector and std::vector::capacity() returns the
total number of elements you can put before the
vector allocates more (and therefore invalidates
iterators).

If you show some code, we can help you more.


Jonathan
 
R

Rennie deGraaf

john said:
in c++ (vc6++) if I have a vector conatiner. I simply add items to a vector
and i want to see how many items I now have.
How do I do this because resize,size,capacity doesnt give the number of
items stored in the vector.

According to the C++ standard, Vector::size() returns the number of
items in a vector, Vector::capacity() returns the number of items that
can fit before it needs to allocate more space, and Vector::resize()
explicitly sets the capacity to a given number of elements. See
http://www.cppreference.com/cppvector/ for more details.

If your implementation of the C++ library is badly broken enough that
these methods do something different, then you should look in a
newsgroup or other documentation specific to your compiler or library.

Rennie
 
J

john townsley

Rennie deGraaf said:
According to the C++ standard, Vector::size() returns the number of items
in a vector, Vector::capacity() returns the number of items that can fit
before it needs to allocate more space, and Vector::resize() explicitly
sets the capacity to a given number of elements. See
http://www.cppreference.com/cppvector/ for more details.

If your implementation of the C++ library is badly broken enough that
these methods do something different, then you should look in a newsgroup
or other documentation specific to your compiler or library.

Rennie

i am using vc6++ and no vecort::size doesnt give you the size. even the help
examples dont show this (i have no idea why?)

.. i had to iterate through to get the number of items in the vector.
 
J

john townsley

john townsley said:
i am using vc6++ and no vecort::size doesnt give you the size. even the
help examples dont show this (i have no idea why?)

. i had to iterate through to get the number of items in the vector.

i used size instead of size() but i didnt get an error, instead i got an
output of 1?
why didnt i get an error?
 
K

Karl Heinz Buchegger

john said:
i used size instead of size() but i didnt get an error, instead i got an
output of 1?
why didnt i get an error?

We are not mind readers. Show code!

Most probably you used the functions address in a place where it
is allowed to do so and didn't clash with the type system.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top