2017-04-30 107 views
0

我想學習C++未聲明的,所以我寫了一個短program.this是我的C++代碼:'CBEGIN' 在此範圍

#include <iostream> 
#include <string> 
#include <regex> 

using namespace std; 

int main() 
{ 
string line; 
regex email(R"(\[email protected](\w+\.)+\w+)"); 
while (getline(cin, line)) { 
    smatch matches; 
    auto current = cbegin(line); 
    auto last = cend(line); 
    while (current != last) 
    { 
     if (regex_search(current, last, matches, email)) 
     { 
      ssub_match match = matches[0]; 
      current = match.second; 
      cout << match.str() << endl; 
     } 
     else 
     { 
      break; 
     } 
    } 
} 
return 0; 
} 

我得到這個錯誤:

=== Build file: "no target" in "no project" (compiler: unknown) === 

C:\Users\Public\Documents\CPP Scripts\usingStringType.cpp||In function 'int main()': 
C:\Users\Public\Documents\CPP Scripts\usingStringType.cpp|13|error: 'cbegin' was not declared in this scope 
C:\Users\Public\Documents\CPP Scripts\usingStringType.cpp|14|error: 'cend' was not declared in this scope 

=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) === 
+0

什麼編譯器?你怎麼稱呼編譯器? –

回答

0

我不知道它們是否在您正在運行的版本中,但是如果它們是,則cbegin/cend應該在< iterator>中。如果他們不是(我猜C++ 14是在他們被添加的時候),你只需要使用line.cbegin()line.cend()