我使用的是 Centos 6.7,安装了 devtools-3 发行版并“启用”它以使 gcc 4.9.2 成为默认设置。使用正则表达式的简单 C++ 程序将编译,但不会链接。
// regex_search example
#include <iostream>
#include <string>
#include <regex>
int main()
{
std::string s("this subject has a submarine as a subsequence");
std::smatch m;
std::regex e("\\b(sub)([^ ]*)"); // matches words beginning by "sub"
std::cout << "Target sequence: " << s << std::endl;
std::cout << "Regular expression: /\\b(sub)([^ ]*)/" << std::endl;
std::cout << "The following matches and submatches were found:" << std::endl;
while (std::regex_search(s, m, e)) {
for (auto x : m) std::cout << x << " ";
std::cout << std::endl;
s = m.suffix().str();
}
return 0;
}
答案1
我可以在这里回答我自己的问题。这是我犯的一个愚蠢的错误。我没有正确安装 devtools-3 发行版。