简体   繁体   中英

Can regex be used with a character array in C++

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:

编译器错误信息

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM