|
Boost Users : |
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2005-07-26 11:41:05
Jarl Friis wrote:
> Hi.
>
> I discovered the following problem using boost::tokenizer. The
> following program should print "hello", but it prints "hell":
>
> #include <iostream>
> #include <boost/tokenizer.hpp>
>
> int main(){
> typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
>
> boost::char_separator<char> sep(",", "");
> tokenizer values(std::string(",hello,"), sep);
Your string is a temporary and goes out of scope. Try:
std::string test(",hello,");
tokenizer values( test, sep );
> for( tokenizer::iterator valueI = values.begin();
> valueI != values.end();
> ++valueI){
> std::cout << "\"" << *valueI << "\"" << std::endl;
> }
> }
>
Jeff
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