以下代码将做什么?为什么用它?
#ifdef _WIN32
#include <direct.h>
#elif defined __linux__
#include <sys/stat.h>
#endif
Run Code Online (Sandbox Code Playgroud) 我刚开始使用OpenGL.这是我的第一个代码:
// OpenGL hello program
#include<iostream>
#include <GL/glut.h>
#include <cstring>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
char message[] = "Hello, world!";
glRasterPos2d(0, 0);
for (int i = 0; i < sizeof(message) / sizeof(message[0]); i++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, message[i]);
}
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitWindowSize(500, 500);
glutCreateWindow("OpenGL hello program");
glutDisplayFunc(display);
glutMainLoop();
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:警告:有符号和无符号整数表达式之间的比较(第9行). 我还尝试编写一个新代码然后看看导致问题的原因:
#include<iostream>
#include <cstring>
void display1() {
char message[] = "Hello, world!";
for (int i = 0; i < sizeof(message) / sizeof(message[0]); i++)
std::cout<<message[i];
} …Run Code Online (Sandbox Code Playgroud)