Boost logo

Boost Users :

From: Peter Gerell (boost_at_[hidden])
Date: 2006-01-31 03:29:22

I believe the example found in example/response_file.cpp and referenced in
the documentation has a bug.

In the following code fragment a temporary string object is passed as the
first argument to the tokenizer constructor.
This string is destroyed before the iteration over the tokens start.

if (vm.count("response-file")) {
  // Load the file and tokenize it
  ifstream ifs(vm["response-file"].as<string>().c_str());
  if (!ifs) {
    cout << "Could not open the response file\n";
    return 1;
  // Read the whole file into a string
  stringstream ss;
  ss << ifs.rdbuf();
  // Split the file content
  char_separator<char> sep(" \n\r");
  tokenizer<char_separator<char> > tok(ss.str(), sep);
  vector<string> args;
  copy(tok.begin(), tok.end(), back_inserter(args));
  // Parse the file and store the options
  store(command_line_parser(args).options(desc).run(), vm);

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at