S
Simon
Hi,
Using a vector as a example, if I have a something like:
std::vector<int> myNumbers;
// ... add items to the vector
and I iterate thru them all,
for( std::vector<int>::const_iterator it = myNumbers.begin();
it != myNumbers.end();
++it )
{
if( it == myNumbers.begin() )
{
// do some stuff with the first element
}
else if( it == /* last element in the container */ )
// <------
{
// do something because this is the last element.
}
else
{
// do something else for elements that are neither first nor last.
}
}
In the code above, how do I tell that this is the last element in the
container?
Many thanks
Simon
Using a vector as a example, if I have a something like:
std::vector<int> myNumbers;
// ... add items to the vector
and I iterate thru them all,
for( std::vector<int>::const_iterator it = myNumbers.begin();
it != myNumbers.end();
++it )
{
if( it == myNumbers.begin() )
{
// do some stuff with the first element
}
else if( it == /* last element in the container */ )
// <------
{
// do something because this is the last element.
}
else
{
// do something else for elements that are neither first nor last.
}
}
In the code above, how do I tell that this is the last element in the
container?
Many thanks
Simon