小编Cod*_*de0的帖子

从内循环c ++内部突破外循环

(我知道有关于此的多个线程,但是在连续搜索5分钟后我无法找到使用C或C++的线程)

我想问一下如何在内循环内部突破外环.

例:

while (true) {
    for (int i = 0; i < 2; i++) {
        std::cout << "Say What?";
        // Insert outer-loop break statement here
    }
}
Run Code Online (Sandbox Code Playgroud)

以上只是一些伪代码.不要担心逻辑.

c++ loops break

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

类原型创建c ++

#include <iostream>    
using namespace std;

class Rectangle;

int main () {
    Rectangle rect (3,4);
    Rectangle rectb (5,6);
    cout << "rect area: " << rect.area() << endl;
    cout << "rectb area: " << rectb.area() << endl;
    return 0;
}

class Rectangle {
    int width, height;
public:
    Rectangle (int,int);
    int area () {return (width*height);}
};

Rectangle::Rectangle (int a, int b) {
    width = a;
    height = b;
}
Run Code Online (Sandbox Code Playgroud)

我知道有很多这样的帖子,但是他们似乎都没有解决我的错误Variable has incomplete type (class_name_here).

我想要做的就是,在主块之后创建类,并通过在主块之前创建"原型"来完全使用它.我想:嗯,这很简单,但是无法修复它.

c++ prototype class

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

GLUT键盘和鼠标功能不会被调用

int main(int argc, const char* argv[])
{
    glutInit(&argc, const_cast<char**>(argv));
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(640, 480);
    glutCreateWindow("Sample Window");
    glutDisplayFunc(render);

    glutMainLoop();
    return 0;
}

void keyboard(unsigned char c, int x, int y){
     std::cout << "Called Keyboard";
    if(c == 'a'){
        exit(0);
    }
}

void mouse(int button, int state, int x, int y){
    std::cout << "Called Mouse";
    if(button == GLUT_RIGHT_BUTTON){
        exit(0);
    }
}

void render(){
}
Run Code Online (Sandbox Code Playgroud)

所以,我对上面的代码有疑问.键盘和鼠标功能不会被调用.

我希望你能设法重现这个问题.

c++ opengl glut listeners

-1
推荐指数
1
解决办法
175
查看次数

标签 统计

c++ ×3

break ×1

class ×1

glut ×1

listeners ×1

loops ×1

opengl ×1

prototype ×1