Reputation: 280
I'm working on a program that cannot use the string library file, instead I am using char arrays. I am able to use regex, and was wondering if there is a way to use regex and character arrays, or even regex and a single char?
The reason why I ask is when I attempt to use my char array in a match the xUtility throws a bunch of errors from the "TEMPLATE CLASS iterator_traits"
if(regex_match(userCommand[3], userCommand[8], isNumeric))
errors:
Upvotes: 3
Views: 7637
Reputation: 385274
std::regex_match
and its friends work through iterators (as well as overloads for not only const std::string&
but const char*
).
So, yes, you can absolutely use a character array rather than std::string
. I advise reading the documentation.
Per your edit:
if(regex_match(userCommand[3], userCommand[8], isNumeric))
If userCommand
is the array, then you are passing in two char
s, not pointers ("iterators").
Try:
if(regex_match(&userCommand[3], &userCommand[8], isNumeric))
or:
if(regex_match(userCommand + 3, userCommand + 8, isNumeric))
Upvotes: 5