2013-04-03 93 views
1
#include <iostream> 
#include <fstream> 
#include <string> 
#include <vector> 
#include <regex.h> 

using namespace std; 

string input; 

int main() 
{ 
    //Input .ply file 
    ifstream inputFile ("input.ply"); 


    //input file is read 
    if (inputFile.is_open()) 
    { 
     int i = 1; //Line iterator 
     int vertices = 0; 
     int faces = 0; 

     vector<float> anatomy; 
     vector<float> normals; 
     vector<int> triangles; 

     string a,line; 
     getline(cin,line); 

     while (inputFile.good()) 
     { 
      //Take number from line 4, set as variable "vertices" 
      if (i == 4) 
      { 
       regex pattern("[^0-9]+"); 
       getline (inputFile,line);    
       vertices = show_match(line, pattern); 
      } 

      //Take number from line 11, set as variable "triangles" 
      if (i == 11) 
      { 
       regex pattern("[^0-9]+"); 
       getline (inputFile,line);    
       faces = show_match(line, pattern); 
      } 

      if (i == 13) 
      { 
       i++; 
       break; 
      } 

      i++; 

     } 

     waitKey(0); 
} 

else 
{ 
    cout << "Cannot read mesh, please try again." << endl; 
} 

return 0; 

} 

只是试图从字符串中读取并提取整数,所以我添加了正则表达式头文件和其他文件以便使用正则表达式。我使用的开发-C++,并已提取的正则表达式的文件到各自LIB包括文件夹“C:\开发-CPP”,但我仍然收到以下错误,当我试图编译我的程序:正则表达式未声明(Dev C++)

“正则表达式”未申报(第一次使用此功能)

+3

哪里'regex.h'从何而来? – chris 2013-04-03 21:32:20

+0

使用'#include '假设你有C++ 11的支持。 – 2013-04-03 21:37:02

+3

如果您使用的是GCC,它不支持C++ 11的正则表达式。 – chris 2013-04-03 21:37:55

回答

0

你会得到从编译器这个错误味精如果没有达到你的发言#include <regex.h>,例如,如果您使用条件包括。

确保#include <regex.h>实际上是达到了。我得到这个错误消息也时我不小心排除包括通过使用条件包括,然后用试图代码。