Wednesday, 15 February 2012

c++ - string iterators incompatible boost::tokenizer -


I have a simple code sample of a class that promotes: Tokenizer.

MyTokenizer.h

#pragma once #include & lt; Iostream & gt; # Include & lt; Boost / tokenizer.hpp & gt; Class MyTokenager {Public: Typed Promotion: Tokensizer & lt; Promote: escaped_list_separator & lt; Four & gt; & Gt; TokType; MyTokenizer (std :: string); ~ Methoconizer () {}; Zero print (); Private: Constant Tokatype Toke_; }; "MyTokenizer.h" includes MyTokenizer :: MyTokenizer :: MyTokenizer (std: string input):

MyTokenizer.cpp

Tok_ (Input ) {Std :: cout & lt; & Lt; Created "tokenizer" from: "& lt; & Lt; Input & lt; & Lt; Std :: endl; (TokType :: iterator = tok_.begin (); it! = Tok_.end (); ++ it) {std :: cout & lt; & Lt; * This is & lt; & Lt; Std :: endl; }} Zero MyTokenizer :: printTok () {std :: cout & lt; & Lt; "Print token" & lt; & Lt; Std :: endl; (TokType :: iterator = tok_.begin (); it! = Tok_.end (); ++ it) {std :: cout & lt; & Lt; * This is & lt; & Lt; Std :: endl; }}

main.cpp

  #include "MyTokenizer.h" int main (zero) {std :: string Input ("a, b, c"); MyTokenager Tow (input); Tok.printTok (); }  

When I run this example, it fixes it through the constructor, prints the expected token in the loop, but to talk to the call to print () it Gives this error

Enter image details here

It seems that I can not construct an Iterator outside of MyTokenizer constructor

edit

I made the printtock () method even easier Given that while still throwing the same error, it looks like this now.

Zero MyTokenizer :: printTok (TokType :: iterator = tok_.begin (); }

OK I have decided myself to have the problem that the string I had made my tokenizer that it was being allocated at the end of the constructor. I fixed it by storing a copy of the input string in my class and creating this string with my tokenizer.


No comments:

Post a Comment