c++ - 未声明的正则表达式 (Dev C++)

标签 c++ regex string integer dev-c++

#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;

}

只是试图从字符串中读取并提取整数,所以我添加了正则表达式 header 和其他文件以便使用正则表达式。我正在使用 Dev-C++,并将用于正则表达式的文件提取到它们各自的 libbininclude 文件夹中,位于“C :\Dev-Cpp",但是当我尝试编译我的程序时仍然收到以下错误:

'regex' undeclared (first use this function)

最佳答案

如果你声明 #include <regex.h>,你将从编译器得到这个错误信息未达到,例如,如果您使用条件包含。

确保#include <regex.h>实际上达到了。当我不小心通过对 使用条件包含排除了包含时,我也收到了此错误消息。然后用 尝试代码.

关于c++ - 未声明的正则表达式 (Dev C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15798525/

相关文章:

c++ - 具有低冲突率的 32 位整数的快速字符串散列算法

java - Java中的char零(0)是什么意思?

c++ - C++ 中 .so 库的核心分割

c++ - 基于 OO 的 C++ 库的 C 和 C++ 接口(interface)

c++ - 黑莓 10 联系人图片到字节数组

c++ - 在 C++ 中为二叉搜索树创建删除函数

javascript - 如何捕获不对称表达末尾的重复组

c# - 使用积极前瞻的 RegEx 的性能和可读性

php - 如何比较数组中的字符串匹配?

regex - 在 vim 上使用正则表达式查找并将所有 href 链接内容替换为 '#' ?