I have the following vector:
std::vector< std::pair<std::string,bool > > myvec;
How can i browse and print elements of my vector with iterators?
What is your problem?
typedef std::vector<std::pair<std::string, bool> > vector_type;
for (vector_type::const_iterator pos = myvec.begin();
pos != myvec.end(); ++pos)
{
std::cout << pos->first << " " << pos->second << std::endl;
}
or you can use std::for_each
with some functor.
Container::iterator iter = myContainer.begin()
)for
-loop, iterate through all elements ( iterator
has operator++
; the end condition is - check if the iterator has reached the end
of your container, like: iter != myContainer.end()
)operator->
.std::pair
is like a struct with two fields - first
and second
, so you can print a vector's element like: iter->first
and iter->second
.