Boost logo

Boost Users :

From: Jarl Friis (jarl_at_[hidden])
Date: 2005-07-27 04:13:06


Serge Skorokhodov <serge.skorokhodov_at_[hidden]> writes:

> Jeff Flinn wrote:
>
>>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 );

Thanks, that helped.

> hm, why thiis works with vc-7_1 then? ;)

I gues accoriding to the standard, it is undefined behaviour, so it
might work, you just can't rely on it.

Jarl


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