【问题标题】:regex_replace doesn't work on Windowsregex_replace 在 Windows 上不起作用
【发布时间】:2013-02-21 17:02:41
【问题描述】:

我在 Linux 上做了一个程序,但现在我想让它与 Windows 兼容。所以我在 Windows 中编译了我的库,创建了一个 Code::Blocks 项目,并开始调整一些不适合 Windows 的函数和变量。

但是有一个函数我不明白为什么它不起作用,regex_replace()。 #include 不会出错,regex_match 也不会。这是我的功能:

string str = "hey guys";
str = regex_replace(string str, regex("guys"), "girls");

“str”现在是“嘿女孩们”。

但是当我在 Windows 上编译时,它给了我这个错误:“没有匹配函数调用 'regex_replace'”。我搜索了一下,但没有发现任何有趣的东西。

那我该怎么办?谢谢!

【问题讨论】:

  • 可能是编译器/标准库版本的问题。您在 Linux 和 Windows 上都使用哪个编译器(和版本)?
  • #include <regexp>了吗?你试过std::regex_replace吗?
  • @aleguna - #include <regex>,而不是 regexp
  • 在 Linux(实际上是 MacOS)上,我使用过 XCode。在 Windows 上,我将 Code::Blocks 与 MinGW 一起使用。我包括 并尝试了 std::regex_replace ;-)

标签: c++ regex windows std


【解决方案1】:

这是代码问题,而不是 Windows 问题。您的代码既不能在 Linux 上编译,也不能在 Windows 上编译:

str = regex_replace(string str, regex("guys"), "girls");
                    ^^^^^^
                    not allowed there

【讨论】:

  • 好吧,这是我不知道的。我尝试使用 str.c_str(),但也没有用。我应该放什么类型的?请注意,它适用于 MacOS ;=)
猜你喜欢
  • 1970-01-01
  • 2016-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-26
  • 2017-06-14
  • 2014-11-01
相关资源
最近更新 更多