1
General / Switch case behaving weirdly
« on: September 24, 2023, 12:20:15 am »
I have this peice of code:
**BEGIN CODE HERE**
my question is why is it that when I press the key "e", the first and the second cases run instead of only the first one being run and the loop being broken?
**BEGIN CODE HERE**
#include "SFML/Graphics.hpp"
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(600, 600), "My window");
sf::Event myEvent;
while (window.isOpen())
{
while (window.pollEvent(myEvent))
{
switch (myEvent.type)
{
case sf::Event::TextEntered:
std::cout << static_cast<char>(myEvent.text.unicode);
std::cout << "pollEventBroken";
break;
case sf::Event::KeyPressed:
if (myEvent.key.code == sf::Keyboard::E)
{
std::cout << '\n';
break;
}
}
}
}
}
**END CODE HERE**#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(600, 600), "My window");
sf::Event myEvent;
while (window.isOpen())
{
while (window.pollEvent(myEvent))
{
switch (myEvent.type)
{
case sf::Event::TextEntered:
std::cout << static_cast<char>(myEvent.text.unicode);
std::cout << "pollEventBroken";
break;
case sf::Event::KeyPressed:
if (myEvent.key.code == sf::Keyboard::E)
{
std::cout << '\n';
break;
}
}
}
}
}
my question is why is it that when I press the key "e", the first and the second cases run instead of only the first one being run and the loop being broken?