#includeint main() { sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window"); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); //Close the window } } window.clear(sf::Color::White); //Draw objects here window.display(); } return 0; }
#includeIn this example, we create a window and use a clock object to close the window automatically after 5 seconds. Once 5 seconds has passed, the `window.close()` function is called to close the window. Package library: SFML libraryint main() { sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window"); //Close the window after 5 seconds sf::Clock clock; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); } } window.clear(sf::Color::White); //Draw objects here window.display(); if (clock.getElapsedTime().asSeconds() > 5) { window.close(); //Close the window after 5 seconds } } return 0; }