所以我的教授给了我一个在 c++ 中使用正则表达式的工作。
所以我尝试在eclipse中编写我的代码(我使用的是linux(ubuntu 12.04))。
所以我拿了代码:
// 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;
}
如您所见,这是一个使用正则表达式的简单代码。
所以我尝试构建它,eclipse给了我一个错误:
Type 'smatch' could not be resolved
并且:
Type 'std::regex' could not be resolved
问题是什么 ?
我试图在合适的位置添加标志 -std=c++0x (properties->c/c++ build ->Miscellaneous),但什么也没发生。
也许我做错了?
也许我必须像在 pthread 中添加指向库的链接?