【问题标题】:Problems using tr1::regex with unicode strings使用带有 unicode 字符串的 tr1::regex 出现问题
【发布时间】:2023-03-30 14:36:01
【问题描述】:
    std::wstring str(L"something");
    std::tr1::wregex rx(L"something");
    std::tr1::wcmatch res;
    std::tr1::regex_search(str, res, rx);       

编译失败,报错:

error C2784: 'bool std::tr1::regex_search(const std::basic_string<_Elem,_StTraits,_StAlloc> &,const std::tr1::basic_regex<_Elem,_RxTraits> &,std::tr1::regex_constants::match_flag_type)' : could not deduce template argument for 'const std::tr1::basic_regex<_Elem,_RxTraits> &' from 'std::tr1::wcmatch'

【问题讨论】:

  • 请注意,GCC 中对&lt;regex&gt; 的编译器支持仍然非常有限——除非您有最先进的版本,否则您可能可以编译,但不能链接。

标签: c++ regex compiler-errors tr1


【解决方案1】:

您应该使用wsmatch,它用于wstring 迭代器,而不是wcmatch,它用于wchar_t*

【讨论】:

  • wsmatch 不会是 wstring,而不是 string
猜你喜欢
  • 1970-01-01
  • 2011-02-13
  • 2014-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-17
  • 1970-01-01
相关资源
最近更新 更多