assert when using cregex_iterator
I have a very simple test program using the latest 1.33 version of regex
library. As soon as I run it, it assert (crash) at the line where
std::string s = (*m1)[0]. I am doing something wrong?
==============
#include "stdafx.h"
#include
Winson Yung wrote:
I have a very simple test program using the latest 1.33 version of regex library. As soon as I run it, it assert (crash) at the line where std::string s = (*m1)[0]. I am doing something wrong?
Yes.
regex header_expr(matchpattern, regex_constants::basic | regex_constants::icase);
POSIX Basic expression don't support \s or the + operator so the regex doesn't do what you think it does and does *not* match the string.
cregex_iterator m1(astring, astring + strlen(astring), header_expr);
std::string s = (*m1)[0]; <==== crash here return 0;
You should always check to see if the iterator is equal to the end of sequence iterator: as it stands you're dereferencing an iterator that doesn't point to anything since no match was found. John.
participants (2)
-
John Maddock
-
Winson Yung