very basic regex scenario works different than my expectation on libstdc++-v3

安稳与你 提交于 2019-12-02 12:11:32

问题


I'm getting a different behavior than my expectation (and also different than Microsoft C++).

Consider the following test.cpp file:

#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;
}

On my Ubuntu Oneiric box, note how I compile the program, and note the output I'm getting from a.out:

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

On the other hand, on my Windows machine, using Visual Studio 2010 I've:

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

I'm not an expert, but Microsoft Visual Studio seems to be the correct answer. This is a very basic scenario, so I wonder what is going on. I can't believe it's a bug, and I can't believe its a fundamental disagreement between MS and GNU at such a basic level. I suspect something in my configuration or in my command line. I got my g++ compiler and headers after installing the default Ubuntu 11.10 client, and 'apt-get install build-essentials'.

Could be a compilation switch that I'm missing, or a fundamental disagreement between MS and GNU


回答1:


<regex> is still largely unimplemented in libstdc++: http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011



来源:https://stackoverflow.com/questions/9804823/very-basic-regex-scenario-works-different-than-my-expectation-on-libstdc-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!