我得到的行为与我的预期不同(也与 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 之间的根本分歧