我正在开发一个不能使用字符串库文件的程序,而是使用字符数组。我可以使用正则表达式,想知道是否有办法使用正则表达式和字符数组,甚至是正则表达式和单个字符?
我问的原因是当我尝试在匹配中使用我的 char 数组时,xUtility 从“TEMPLATE CLASS iterator_traits”中抛出一堆错误
if(regex_match(userCommand[3], userCommand[8], isNumeric))
错误:
最佳答案
std::regex_match
及其 friend 通过迭代器工作(以及不仅是 const std::string&
的重载,还有 const char*
的重载)。
所以,是的,您绝对可以使用字符数组而不是 std::string
。我建议阅读文档。
根据您的修改:
if(regex_match(userCommand[3], userCommand[8], isNumeric))
如果 userCommand
是数组,那么您将传入两个 char
,而不是指针(“迭代器”)。
尝试:
if(regex_match(&userCommand[3], &userCommand[8], isNumeric))
或:
if(regex_match(userCommand + 3, userCommand + 8, isNumeric))
关于c++ - 正则表达式可以与 C++ 中的字符数组一起使用吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21321324/