Boost logo

Boost Users :

From: CN (cnliou9_at_[hidden])
Date: 2005-10-05 00:27:58


Hi!

The following version incorrectly produces the result:

< > 1

//----------------------
#include<iostream>
#include<boost/tokenizer.hpp>
#include <vcl.h>
#pragma hdrstop
#pragma argsused
int main(int argc, char* argv[])
{
  using namespace std;
  using namespace boost;
  AnsiString As = "*";
  typedef tokenizer<boost::char_separator<char> > Tok;
  char_separator<char> sep(", ");
  Tok tokens(string(As.c_str(),As.Length()), sep);
  for(Tok::iterator tok_iter = tokens.begin();tok_iter != tokens.end();
      ++tok_iter)
    cout << "<" << *tok_iter << "> " << (*tok_iter).size();
  return EXIT_SUCCESS;
}
//----------------------

However, this version correctly outputs this result:

<*> 1

#include<iostream>
#include<boost/tokenizer.hpp>
#include <vcl.h>
#pragma hdrstop
#pragma argsused
int main(int argc, char* argv[])
{
  using namespace std;
  using namespace boost;
  AnsiString As = "*";
  string str=string(As.c_str(),As.Length());
  typedef tokenizer<boost::char_separator<char> > Tok;
  char_separator<char> sep(", ");
  Tok tokens(str, sep);
  for(Tok::iterator tok_iter = tokens.begin();tok_iter != tokens.end();
      ++tok_iter)
    cout << "<" << *tok_iter << "> " << (*tok_iter).size();
  return EXIT_SUCCESS;
}
//----------------------

Why the firt version mulfunctions?

TIA and Regards,

CN

-- 
http://www.fastmail.fm - A fast, anti-spam email service.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net