0

I am quite new in C++ and at some point I try to figure out how to measure the size of a dynamic array. To be more specific lets say I define:

std::vector<int> dirichNodes;

and then after some operations I filled that vector. Later I would like to see its entries like:

    for (int i=0; i<????(size of dirichNodes vector); i++)
{

std::cout<<dirichNodes[i]<<std::endl;

}

what i would like to know is what to insert in the place of ???? here.

Any suggestions appreciated, thanks in advance.

1
  • 6
    It seems you need to look for a good reference. Commented Dec 9, 2014 at 14:24

1 Answer 1

4

vector::size() will return the number of elements in a vector.

for (int i=0; i<dirichNodes.size(); i++)
{
    std::cout<<dirichNodes[i]<<std::endl;    
}
Sign up to request clarification or add additional context in comments.

1 Comment

A more idiomatic way would be to use a ranged based for or use iterators

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.