Is this a bug of boost::tokenizer ?

This is a discussion on Is this a bug of boost::tokenizer ? within the C++ Programming forums, part of the General Programming Boards category; Here is the code. When Code: string line("dd-9c32d00@3"); is changed to Code: string line("dd-9c32d00"); The program crashes. It seems that ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    Is this a bug of boost::tokenizer ?

    Here is the code. When
    Code:
    string line("dd-9c32d00@3");
    is changed to
    Code:
    string line("dd-9c32d00");
    The program crashes.
    It seems that tok.end() does not bound the end of string parsing?

    Code:
    #include <boost/tokenizer.hpp>                                                               
    using namespace std;                                                                                                            
    using namespace boost;
    
    int main(){
        //string line("dd-9c32d00@3");
        string line("dd-9c32d00");// crashes!
        typedef boost::tokenizer< boost::char_separator<char> > token;
        boost::char_separator<char> sep("@");
        token tok(line, sep);
                                                                                                                                               
        token::iterator itt=tok.begin();                               
        if (itt==tok.end())                                                                                                        
            cout<<*itt; 
        else                                                                                                         
            cout<<*(++itt);
                                                                                                                                                                                 
        return 0;                   
    }
    Last edited by meili100; 03-14-2008 at 07:06 PM.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    284
    My question actually is, how to tell if 'itt' is the last piece delimited by the token? I compared it with tok.end(). If false it is not, otherwise it is.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Read the example.

    If the iterator is pointing to the end of the tokenizer, then you *don't* want to access the iterator, as it does not contain a valid token.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gaks bug?
    By Yarin in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-31-2008, 02:47 PM
  2. Debugging a rare / unreproducible bug..
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 08-05-2008, 12:56 PM
  3. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 12:02 AM
  4. ATL bug of CComPtr?
    By George2 in forum Windows Programming
    Replies: 6
    Last Post: 04-07-2008, 07:52 AM
  5. Annoying bug I can't find or fix!
    By homeyg in forum C++ Programming
    Replies: 3
    Last Post: 11-20-2004, 11:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21