3

我正在尝试使用正则表达式。所以我在 VS 2010 中创建了一个项目,在顶部我放了:

#include "std_lib_facilities.h"
#include <regex>
using namespace std::tr1;

int main()
{
    regex rx("123");
    cout << ">";
    string s;
    getline(cin,s);
    regex_match(s.begin(),s.end(),rx);
    cout << '\n' << s << endl;
    keep_window_open();
}

当我编译时,我得到一个错误列表,看起来 regex.h 文件本身存在问题。以下是错误:

Error   1   error C2977: 'Vector' : too many template arguments c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    982
Error   2   error C2146: syntax error : missing ';' before identifier '_MyCont' c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    982
Error   3   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    982
Error   4   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    982
Error   5   error C2653: '_MyCont' : is not a class or namespace name   c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    986
Error   6   error C2146: syntax error : missing ';' before identifier 'const_iterator'  c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    986
Error   7   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    986
Error   8   error C2868: 'std::tr1::match_results<_BidIt,_Alloc>::const_iterator' : illegal syntax for using-declaration; expected qualified-name   c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    986
Error   9   error C2146: syntax error : missing ';' before identifier '_Matches'    c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    1195
Error   10  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    1195
Error   11  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    1195
Error   12  error C1903: unable to recover from previous error(s); stopping compilation c:\program files (x86)\microsoft visual studio 10.0\vc\include\regex    1428

我该如何解决这个问题并让程序运行?谢谢

4

0 回答 0