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++)
「正則表達式」未申報(第一次使用此功能)
哪裏'regex.h'從何而來? – chris 2013-04-03 21:32:20
使用'#include'假設你有C++ 11的支持。 –
2013-04-03 21:37:02
如果您使用的是GCC,它不支持C++ 11的正則表達式。 – chris 2013-04-03 21:37:55