[英]Why is exit(0) giving me errors?
So I've been following a tutorial and when I tried to compile the below code: 因此,我一直在遵循教程,并在尝试编译以下代码时:
#include <glut.h>
#include <iostream>
void render(void);
void keyboard(unsigned char c, int x, int y);
void mouse(int button, int state, int x, int y);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Test GLUT App");
glutDisplayFunc(render); // render
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop(); // initialization finished. start rendering
}
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.5, 0.2, 0.9);
glVertex2f(-0.5, -0.5);
glColor3f(0.1, 0.2, 0.5);
glVertex2f(0.0, -0.5);
glColor3f(0.3, 0.9, 0.7);
glVertex2f(0.0, 0.5);
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char c, int x, int y)
{
if(c == 27)
{
exit(0);
}
}
void mouse(int button, int state, int x, int y)
{
if(button == GLUT_RIGHT_BUTTON)
{
exit(0);
}
}
I get 3 errors out of nowhere: 我从无处得到3个错误 :
Error 1 error C2381: 'exit' : redefinition; 错误1错误C2381:'退出':重新定义; __declspec(noreturn) differs c:\\program files (x86)\\microsoft visual studio 10.0\\vc\\include\\stdlib.h 353
__declspec(noreturn)与c:\\ program files(x86)\\ microsoft visual studio 10.0 \\ vc \\ include \\ stdlib.h 353不同
Error 2 error C3861: 'exit': identifier not found ....main.cpp 45 错误2错误C3861:'退出':找不到标识符.... main.cpp 45
Error 3 error C3861: 'exit': identifier not found ....main.cpp 53 错误3错误C3861:'退出':找不到标识符.... main.cpp 53
Does anyone see why this error appears? 有人看到这个错误的原因吗? Im using VS2010.
我正在使用VS2010。
You need to #include <cstdlib>
. 您需要
#include <cstdlib>
。
edit: 编辑:
You are probably following a very known tutorial that provides a header file for you. 您可能正在遵循一个非常知名的教程,该教程为您提供了头文件。
This will help you then GLUT exit redefinition error 这将帮助您然后GLUT退出重新定义错误
如果您的Visual Studio抛出构建错误,提示IntelliSense无法识别“退出”,则您必须包含process.h
Try adding using namespace std
to the top. 尝试在顶部
using namespace std
添加。 I'm not sure if this will fix it but i had a similar error earlier and that fixed it. 我不确定这是否可以解决问题,但是我之前有一个类似的错误,并且可以解决。 good luck.
祝好运。
u need to declare header simple as work , works in my comp 您需要将header声明为work,可以在我的comp中使用
#include <stdlib.h>
#include <cstdlib>
#include <glut.h>
#include <iostream>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.