# sfml drawing text c++

using visual studio 2015 and SFML . relevant code:

sf::Font font;
font.loadFromFile("Arial.ttf");
sf::Text text;
text.setFont(font);
text.setString("hello ");
_mainWindow.draw(text);


It doesn't display the text. I put a breakpoint, the font gets the correct value. but the text's string stays empty. for the main window I get: + _mainWindow sf::RenderWindow

Can anybody help?

thanks

• Could you share some code around this. Is this in a method? A class? Could you show how it is called? How is _mainWindow actually passed to it?
– user35344
Feb 26 '17 at 10:44

## 2 Answers

If your font goes out of scope, the text will not be able to display. SFML fonts need to stay for the scope of the text that uses them. (I can't tell very much because I don't have surrounding code, however).

Are you calling _mainWindow.clear(); before _mainWindow.draw() and _mainWindow.display(); after it ?