我正在使用 sfml 库进行某种图形工作,我想存储我使用键盘输入的文本,但它显示错误 请告诉我这是怎么可能的:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s="";
sf::Window window(sf::VideoMode(800, 200), "Ludo",sf::Style::Default);
window.setKeyRepeatEnabled(false);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
else if (event.type == sf::Event::EventType::TextEntered)
{
s += event.type.unicode;
}
}
window.display();
}
return 0;
}
错误是:
sf::Event event, expression must have a class type
最佳答案
你的问题是这一行:
s += event.type.unicode;
event.type
是一个描述事件类型的字段(您在上面的案例检查中使用了它)。
然后您尝试访问成员 unicode
,这显然失败了,因为 type
在这里不是类或结构。您真正想要的是字段 sf::Event::text
,它是一个结构。
因此,这一行必须如下所示:
s += event.text.unicode;
关于c++ - 无法在 SFML 2.4 中存储文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47846411/