【问题标题】:very basic regex scenario works different than my expectation on libstdc++-v3非常基本的正则表达式场景与我对 libstdc++-v3 的预期不同
【发布时间】:2012-03-21 12:41:40
【问题描述】:

我的行为与我的预期不同(也与 Microsoft C++ 不同)。

考虑以下 test.cpp 文件:

#include <iostream>
#include <ostream>
#include <regex>

int main( void )
{
    std::regex rx( "a(b+)(c+)d" );
    std::string s( "abbbbccd" );
    std::smatch m;

    bool f = regex_match( s, m, rx );
    std::cout << std::boolalpha << f << std::endl;
    if( f ) {
        std::cout << "m[1]=" << m[1] << std::endl;
        std::cout << "m[2]=" << m[2] << std::endl;
    }

    return 0;
}

在我的 Ubuntu Oneiric 机器上,记下我是如何编译程序的,并记下我从 a.out 得到的输出:

$ g++ -std=c++0x test.cpp
$ ./a.out
true
m[1]=abbbb
m[2]=bcc

另一方面,在我的 Windows 机器上,我使用 Visual Studio 2010:

C:> cl /EHsc test.cpp
C:> test.exe
true
m[1]=bbbb
m[2]=cc

我不是专家,但 Microsoft Visual Studio 似乎是正确的答案。这是一个非常基本的场景,所以我想知道发生了什么。我不敢相信这是一个错误,我不敢相信这是 MS 和 GNU 在如此基本的层面上的根本分歧。我怀疑我的配置或命令行中有什么东西。在安装默认的 Ubuntu 11.10 客户端和“apt-get install build-essentials”后,我得到了我的 g++ 编译器和头文件。

可能是我缺少的编译开关,或者是 MS 和 GNU 之间的根本分歧

【问题讨论】:

标签: c++ regex g++ c++11 libstdc++


【解决方案1】:

&lt;regex&gt; 在很大程度上仍未在 libstdc++ 中实现:http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    • 2018-06-04
    • 2021-03-24
    • 2015-10-18
    相关资源
    最近更新 更多