小编Bos*_*nia的帖子

为什么有条件地包含direct.h或sys/stat.h基于_WIN32或__linux__?

以下代码将做什么?为什么用它?

  #ifdef _WIN32
  #include <direct.h>
  #elif defined __linux__
  #include <sys/stat.h>
  #endif
Run Code Online (Sandbox Code Playgroud)

c ifdefine

5
推荐指数
1
解决办法
5890
查看次数

有符号和无符号整数表达式之间的比较

我刚开始使用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)

c++ compiler-errors

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

c ×1

c++ ×1

compiler-errors ×1

ifdefine ×1