Tokenizer: BCB AnsiString and std:string

Hi!
The following version incorrectly produces the result:
< > 1
//----------------------
#include<iostream>
#include

CN wrote:
The first version creates a temporary string that only exists for long enough to call tokens' constructor, and a tokenizer keeps pointers into the string it was built on, not a list of the tokens (for space reasons), so immediately after tokens is constructed, it has a list of pointers to a dead variable (this is a Bad Thing, and you are lucky this didn't work the first time, rather than silently stop working later). The second version has a real variable holding the string, and therefore the pointers are still alive. Why don't you just use 'As' directly? Does AnsiString not provide begin()/end()? If it's just that it's versions are differently named you can do: Tok tokens(As.Begin(), As.End(), sep);// Or whatever begin()/end() are PS: It's conventional to name variables with a lower-case first letter.
participants (2)
-
CN
-
Simon Buchan