C++ 无法在SFML 2.4中存储文本

C++ 无法在SFML 2.4中存储文本,c++,sfml,C++,Sfml,我正在使用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::Sty

我正在使用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;
 }
#包括
#包括
#包括
使用名称空间std;
int main()
{
字符串s=“”;
sf::Window窗口(sf::VideoMode(800200),“Ludo”,sf::Style::Default);
window.setKeyRepeatEnabled(假);
while(window.isOpen())
{
sf::事件;
while(window.pollEvent(事件))
{
如果(event.type==sf::event::Closed)
{
window.close();
}
else if(event.type==sf::event::EventType::textcentered)
{
s+=event.type.unicode;
}
}
window.display();
}
返回0;
}
错误是:

sf::事件,表达式必须具有类类型


您的问题是这一行:

s += event.type.unicode;
event.type
是一个描述事件类型的字段(您在上面的案例检查中使用过它)

然后您尝试的是访问一个成员
unicode
,这显然是失败的,因为
type
在这里不是类或结构。您实际需要的是字段
sf::Event::text
,它是一个结构

因此,该行必须如下所示:

s += event.text.unicode;

@ALIHAMZABASHIR按照您的方式应该可以做到这一点,但是您可能必须手动构造一个要追加的string对象。