views:

129

answers:

1

When I retrieve the begin() iterator of a boost::tokenizer, I get a crash in msvcp90d.dll, that says "ITERATOR LIST CORRUPTED", which looks suspiciously like issues I have run into before with the _HAS_ITERATOR_DEBUGGING compiler flag, however I have verified that my program is being compiled with this flag turned off.

Here is the program:

#include <sstream>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>


int main(int argc, char* argv[])
{
    std::string data("gobo;wimbley;red;moki;boober");
    std::ostringstream input;
    input << data;


    std::string mystr(input.str());
    boost::char_separator<char> separator(";");
    boost::tokenizer<boost::char_separator<char>> tok(mystr, separator);
    boost::tokenizer<boost::char_separator<char>>::iterator iter = tok.begin();
}

Interestingly, if I replace the instantiation of the tokenizer with the following line, it works:

    boost::tokenizer<boost::char_separator<char>> tok(data, separator);

So it appears to be something related to the ostringstream. Any ideas?

+3  A: 

There is a bug in Visual C++ with std::ostringstream when _HAS_ITERATOR_DEBUGGING is disabled.

If I recall correctly, the std::string copy constructor copies iterators. You can get around this by using the std::string conversion constructor taking a char* instead.

If you change

std::string mystr(input.str());

to

std::string mystr(input.str().c_str());

then no exception is thrown.

James McNellis