【问题标题】:Basic C++ SFML Display Window Error基本 C++ SFML 显示窗口错误
【发布时间】:2014-10-10 22:23:24
【问题描述】:

我是一名初级 C++ 程序员,目前正在使用 SFML。我将 Eclipse CDT 与 MinGW GCC 一起使用,我正在尝试使用在 http://sfml-dev.org/tutorials/2.1/start-cb.php 找到的源代码创建一个基本窗口。我把代码放进去,显然它不起作用。我尝试包含库、链接器路径、包含路径、包含文件和所有内容,但它似乎对我不起作用。

代码:

#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Application");
    sf::CircleShape shape;
    shape.setRadius(40.f);
    shape.setPosition(100.f, 100.f);
    shape.setFillColor(sf::Color::Cyan);
    while (window.isOpen())
    {
    sf::Event event;
    while (window.pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
            window.close();
    }
    window.clear();
    window.draw(shape);
    window.display();
    }
}

我的控制台出现错误,例如“'window' not defined in this scope”、“'shape' not defined in this scope”、“expected ; before 'shape'”等。

有谁知道为什么,谁能帮帮我?

【问题讨论】:

  • 信息不足。如果您遇到错误,不要只是描述它,提供完整的信息......尤其是“不起作用”不是问题描述。最后,您需要实际提供有关您使用的设置的信息。

标签: c++ sfml


【解决方案1】:

我建议你先试试这样的:

#include <SFML\System.hpp>

int main()
{return 0;}

只是为了确保正确设置包含路径。

然后你可以尝试设置库路径,链接系统模块库并使用其中的一些类。

那么你也可以尝试使用其他模块,确保以正确的顺序链接它们,参见"getting started with SFML"

【讨论】:

    猜你喜欢
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 2022-01-21
    • 2020-01-08
    相关资源
    最近更新 更多