0

I am trying to use a graphics library (SFML) for c++, and I am having issues. I use Visual Studio 2017. I have watched many Youtube tutorials, and get the same error with every one I try. I can't find the solution, as people are saying "the folders need to be together" which I have already done: enter image description here Here are the errors I get:

E1696 cannot open source file "stdafx.h" c:\Users\George\source\repos\Game\Game\main.cpp 1

E0065 expected a ';' c:\Users\George\source\repos\Game\Game\main.cpp 5

E1696 cannot open source file "SFML/Graphics.hpp" c:\Users\George\source\repos\Game\Game\main.cpp 2

C1083 Cannot open include file: 'stdafx.h': No such file or directory c:\users\george\source\repos\game\game\main.cpp 1

The code I am running (copied, with extra):

#include <stdafx.h>
#include <SFML/Graphics.hpp>
using namespace std

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

Before, the code did not have the stdafx.h or namespace std so I had to add them because I had other errors. I would greatly appreciate any help. Thanks

nvoigt
  • 75,013
  • 26
  • 93
  • 142
George_E -old
  • 188
  • 1
  • 3
  • 17
  • *"Before, the code did not have the stdafx.h or namespace std so I had to add them because I had other errors."* -- You should have asked about those errors instead. – Benjamin Lindley Dec 15 '17 at 20:51
  • Best advice I can give is to pick up a book from [this list](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and *read* it. – Jesper Juhl Dec 15 '17 at 20:52
  • @BenjaminLindley Yeah but stdafx is required in VS 2017? – George_E -old Dec 15 '17 at 20:54
  • 5
    @George_E: No. It is not. – Benjamin Lindley Dec 15 '17 at 20:54
  • @BenjaminLindley I took it away and get "Can't open source file: 'SFML/Graphics.hpp' " – George_E -old Dec 15 '17 at 20:57
  • @George_E: Like I said. You should have asked about those original errors. – Benjamin Lindley Dec 15 '17 at 20:58
  • @BenjaminLindley I don't want to write it out all again though ): – George_E -old Dec 15 '17 at 20:59
  • @BenjaminLindley If I get rid of namespace std as well I get: Severity Code Description Project File Line Suppression State Error (active) E0276 name followed by '::' must be a class or namespace name Game c:\Users\George\source\repos\Game\Game\main.cpp 7 – George_E -old Dec 15 '17 at 21:00
  • Don't follow random Youtube tutorials. [This](https://www.sfml-dev.org/tutorials/2.4/start-vc.php) is the official tutorial. It's text, because you will need to have it side-by-side with your screen and you will need to do what it says *at your speed*, not at the speed of some random youtube guy. Please follow it *to the letter* and you will be able to get this running. – nvoigt Dec 18 '17 at 09:42
  • @nvoigt Forgot to post answer to my own question, but now I have. I figured out that I had it say the wrong type of system – George_E -old Dec 18 '17 at 17:44

1 Answers1

0

Figured it out a few days ago, but forgot to post how I fixed it. I downloaded the 32-bit version of SFML. In properties, you need to make sure it says: "Active(win32)" or something like that. I had mine on "x64" which is why it didn't work. Hope this helped someone else with the same problem :)

George_E -old
  • 188
  • 1
  • 3
  • 17