C ++ Opengl fstream ctype.h错误

时间:2016-11-02 12:34:23

标签: c++ opengl fstream

我正在进行一项要求我包含fstream库的作业。这是我的代码:

#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
#include <fstream>
#include <GL/gl.h>
#include <GL/glut.h>
#include <ctype.h>

using namespace std;

void drawPolyLine() {
    fstream inStream;
    inStream.open("dino.dat", ios::in);
    if (inStream.fail()) return;
    //glClear(GL_COLOR_BUFFER_BIT);
    GLint numPolys,  numLines, x, y;
    inStream >> numPolys;
    for (int j = 0; j < numPolys; j++)
    {
        inStream >> numLines;
        glBegin(GL_LINE_STRIP);
        for (int i=0; i< numLines;  i++)
        {
            inStream >> x >> y;
            glVertex2i(x, y); 
        }
        glEnd();
    }
    inStream.close();
}

void DrawTilling2(){
    glClear(GL_COLOR_BUFFER_BIT);
    for(int i = 0; i < 10; i++)
        for(int j = 0; j < 10; j++){
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            if((i + j) % 2 == 0) gluOrtho2D(0, 640, 0, 440);
            else gluOrtho2D(0, 640, 440, 0);

            glViewport(i * 64, j * 44, 64, 44);
            drawPolyLine();
        }

    glFlush();
}

void DrawTilling(){
    glClear(GL_COLOR_BUFFER_BIT);
    for(int i = 0; i < 10; i++)
        for(int j = 0; j < 10; j++){
            glViewport(i * 64, j * 44, 64, 44);
            drawPolyLine();
        }
    glFlush();
}

void Init() {
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glColor3f(0.0f, 0.0f, 0.0f);
    glPointSize(4.0);
    glMatrixMode(GL_PROJECTION); 

    glLoadIdentity();
    gluOrtho2D(0, 640, 0, 480);
    glViewport(0, 0, 640, 480);
}

int main(int argc, char** argv) {
    glutInit(&argc,  argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(640, 480);
    glutInitWindowPosition(100, 150);
    glutCreateWindow("Tilling  dinosaurus");
    glutDisplayFunc(DrawTilling2);
    Init();
    glutMainLoop();
    return 0;
}

然而,当我尝试编译它时,它显示与ctype.h相关的错误(我的代码中根本没有包含它)。这是编译日志:

Compiler: TDM-GCC 4.8.1 32-bit Profiling
Building Makefile "U:\Campus\5th Semester\Computer Graphics\T4 GRAFKOM\dino\Makefile.win"
Executing  make...
mingw32-make.exe -f "U:\Campus\5th Semester\Computer Graphics\T4 GRAFKOM\dino\Makefile.win" all
g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -m32 -pg -g3

In file included from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\cctype:42:0,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\localefwd.h:42,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\ios:41,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\istream:38,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\fstream:38,
                 from main.cpp:3:
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\ctype.h:4:13: error: redefinition of 'const int A'
 const int   A = 500;  /* length of a side of the monitor window */
             ^

In file included from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\winnt.h:16:0,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\minwindef.h:146,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\windef.h:8,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\windows.h:69,
                 from main.cpp:2:

c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\ctype.h:4:13: error: 'const int A' previously defined here
 const int   A = 500;  /* length of a side of the monitor window */
             ^
In file included from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\cctype:42:0,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\localefwd.h:42,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\ios:41,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\istream:38,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\fstream:38,
                 from main.cpp:3:
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\ctype.h:5:13: error: redefinition of 'const float B'
 const float B = 500;  /* length of a side of the clipping rectangle */

             ^

In file included from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\winnt.h:16:0,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\minwindef.h:146,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\windef.h:8,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\windows.h:69,
                 from main.cpp:2:

c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\ctype.h:5:13: error: 'const float B' previously defined here

 const float B = 500;  /* length of a side of the clipping rectangle */
             ^
In file included from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\cctype:42:0,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\bits\localefwd.h:42,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\ios:41,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\istream:38,
                 from c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++\fstream:38,
                 from main.cpp:3:
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\ctype.h:6:13: error: redefinition of 'const float C'
 const float C = 200;  /* length of a side of the square the program draws */
             ^
In file included from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\winnt.h:16:0,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\minwindef.h:146,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\windef.h:8,
                 from c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\windows.h:69,
                 from main.cpp:2:
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\ctype.h:6:13: error: 'const float C' previously defined here
 const float C = 200;  /* length of a side of the square the program draws */
             ^


U:\Campus\5th Semester\Computer Graphics\T4 GRAFKOM\dino\Makefile.win:29: recipe for target 'main.o' failed
mingw32-make.exe: *** [main.o] Error 1

Execution terminated

(省略了部分日志)。

我在Windows 10上使用Dev-Cpp 5.4.1。

1 个答案:

答案 0 :(得分:0)

仔细检查,您没有损坏ctype.h标题。这些错误看起来就像是偶然的一些变量定义本来是以某种方式在那里结束了。