知道为什么下面的代码会打印“不匹配”吗?与编译器或库版本有关的东西?我用 g++ a.cpp 编译。
#include <tr1/regex>
#include <iostream>
#include <string>
using namespace std;
int main()
{
const std::tr1::regex pattern("(\\w+day)");
std::string weekend = "Saturday and Sunday";
std::tr1::smatch result;
bool match = std::tr1::regex_search(weekend, result, pattern);
if(match)
{
for(size_t i = 1; i < result.size(); ++i)
{
std::cout << result[i] << std::endl;
}
}else
std::cout << "no match" << std::endl;
return 0;
}