Parsing comma/space separated values in C++

I use environment variables for changing the behaviour of an application. I try not to have too many variables as it becomes difficult to remember what they are. As such I set a number of parameters into a single environment variable using a comma/space separated list and read the list as follows:
#include 
using namespace boost;

const char *st = getenv("APP_VERBOSE");
if (st != NULL)
{
  std::string stV(st);
  char_separator sep(", ");
  tokenizer< char_separator > tokens(stV, sep);
  FOREACH( const string &t, tokens)
  {
    if (t == "verbose")
    {
      // set a verbose flag
    }
    else if (t == "help")
    {
      // output all the options...
    }
  }
}
I am using boost here because it is more portable.

Comments