STL

Advanced STL

Sample code to explain some advanced STL concepts.

//
// STL.cpp
// Sample code to explain some advanced STL concepts. This is a shameless
// copy of online materials in order to create a simple example program to
// explain the basics of STL.
//
// Topics covered:
// ostream_iterator, copy, deque, insert_iterator, front_inserter,
// back_inserter, accumulate, count, count_if, find, find_if, generate,
// generate_n, fill, fill_n, transform, negate, mismatch, search, equal,
// for_each, swap, sort, merge, binary_search, includes, ptr_fun, set_union,

How to iterate vector in a loop and delete items from it?

You can't just iterate vector in a for loop and delete the item pointed by the iterator and increment that iterator at the end of the loop, as after deleting the item from the vector, the iterator is invalidated.

The crude way of deleting the items in a vector is:

typedef std::vector<std::string> string_vector;
typedef std::vector<std::string>::iterator string_vector_iterator;

string_vector_iterator iter = m_vPaths.begin();
while (iter != m_vPaths.end())
{
  if(::DeleteFile(iter->c_str()))
  {