为什么我的程序在进入main()之前停止工作

时间:2017-04-18 09:47:36

标签: c++ visual-studio sfml

所以我今天醒来,打开我的项目并尝试运行它 - 幸运的是,它甚至在进入主要功能之前就停止了。

然而,它昨晚有效,但现在不起作用。我没有做任何改变它。

这是source.cpp

#include <SFML/Graphics.hpp>
#include "Game.h"
#include <iostream>

using namespace std;


int main()
{
    string name;
    cout << "alupigus";

    name = "Dino Attack";

    Game game(800, 800, name);

    game.loadAssets();

    game.Run();

    return 0;
}

当我在控制台中编译并运行它时,它除了显示黑屏外没有显示任何内容。我无法输入任何内容,SFML的渲染窗口也没有出现。

我只使用SFML作为外部库,但我没有修改任何链接,也没有移动文件等。

2 个答案:

答案 0 :(得分:1)

你没有冲洗流。您的代码应如下所示:

#include <SFML/Graphics.hpp>
#include "Game.h"
#include <iostream>

using namespace std;


int main()
{
    string name;
    cout << "alupigus" << endl;

    name = "Dino Attack";

    Game game(800, 800, name);

    game.loadAssets();

    game.Run();

    return 0;
}

另外,请考虑删除 using namespace std;,因为在较大的项目中这是不好的做法。阅读this

答案 1 :(得分:0)

好吧基本上我解决了这个问题。由于某些原因,这阻止了程序正常运行,尽管我没有触及代码的这个区域一周

x = Board::dinozaurPoz;
        x.x = rand() % 400 + 200;
        while (Board::matrix[(int)x.y / 40][(int)x.x / 40] != 1) {
            x.x = rand() % 400 + 200;
循环不会无限期地运行,所以我真的不知道这里的问题是什么。也许更有经验的人可以告诉我我做错了什么。

相关问题