STL

Website Customer Visit Count

Question: A leading shopping website generates logs everyday of customers visiting their website along with the page number that they visited. Each entry contains the customer unique id and the page id, which the customer visited. Given the logs of 3 days, and the customer id, check whether the customer visited exactly on 2 out of 3 days and also check whether he visited more than 3 different pages?

#include <iostream>
#include <hash_map>
#include <list>
#include <set>
#include <bitset>
#include <string>

using namespace std;

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()))
  {