Since others have already answered your main question and commented on the most important stuff I'll just follow up with a few minor nits:
#include <SFML\System.hpp>
You should use frontslashes "/" consistently when including files (and working with file paths in general), not backslashes "\".
Front slashes work with all compilers and on all operating systems, backslashes only work on Windows (and maybe VMS - can't remember for sure). Also backslashes have to be escaped "\\" in many contexts which you don't have to worry about if you use frontslashes. So just use "/" always.
sf::Event event;
sf::Event event2;
sf::Event event3;
int main() {
As others have already said, you only need a single sf::Event, but that's not what I wanted to comment on here. What I want to say is that you really,
really,
really want to avoid global variables and especially global variables of SFML types.
To quote from
an older post of mine (and
another one):
Global variables bring you all sorts of headaches; like:
- It's hard to keep track of where they are read/written since they are not encapsulated.
- Different objects each using the same global variable become very tightly coupled (and you should try to minimize coupling between your classes).
- Global variables in different translation units have undefined order of initialization, so you can't count on one being initialized before another.
- Global variables are constructed before entering main() and destroyed after leaving it which means that they operate in a world where certain things that you assume about your runtime environment may not be true.
- Since they are visible to your entire project, changing one of them potentially requires recompilation of a lot of files.
And more. Just say no. Friends don't let friends use global variables
Just don't use globals - they are not worth the trouble.
...
return -1; // error
...
return 0;
...
Those are rather bad values to use for return values from main(). Although in general the rule is that main returns zero for success and non-zero for failure, the only standardized values you can really count on across different systems are the EXIT_SUCCESS and EXIT_FAILURE macros from the <cstdlib> header (and no, EXIT_SUCCESS isn't actually 0 on all operating systems although it probably is for all you care about). Especially returning -1 is a bad idea since not all systems deal sanely with negative return values from main. For example, on Linux the return value from main is actually "the_value_you_provide & 0377" so, for example "return -1" becomes an actual return code of 255, "return -3" becomes 253 and "return 123456" becomes 64 - see where that could become confusing when the operating system tells you that the program exited with error code 255 and you then can't find that anywhere in your code?
Just stick to only ever returning EXIT_SUCCESS and EXIT_FAILURE from main() and you'll be fine on all platforms and compilers.
Ohh and finally, I can recommend
clang format if you want a tool to help you format your code consistently (makes it easier to read).
Edit: Forgot one thing I wanted to also mention;
You probably want to use
sf::Window::setVerticalSyncEnabled rather than
sf::Window::setFramerateLimit when you can. Vsync gives a much better result when it works (is not disabled in drivers). Just remember to never use both at the same time. They interact badly. Only ever use one or the other.