Visual studio error

I am getting a very annoying error while trying to compile my code,

everything looks fine but I'm getting an error saying I am forgetting to include a file WHICH I am NOT

Severity Code Description Project File Line Suppression State
Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? ConsoleApplication2 c:\users\user\source\repos\consoleapplication2\consoleapplication2\source.cpp


how can I fix this and why is this happening?

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include "stdafx.h"
#include <stdlib.h>
#include <WinSock2.h>
#include <iostream>
#include <Windows.h>



#pragma comment(lib,"ws2_32.lib")

using namespace std;

int main()
{

	cout << "hello" << endl;
	system("pause");
    return 0;
}
I turned off precompiled headers


Severity Code Description Project File Line Suppression State
Error C2059 syntax error: '}' ConsoleApplication2 c:\users\user\source\repos\consoleapplication2\consoleapplication2\source.cpp 2

but line 2 is a pre processor directive and not a statement so how am I missing a semi colon and curly brace?

I've only been using visual studio for 30 mins and already I'm not liking it

anybody know whats going wrong?
The easiest is to set the options Precompiled Headers->Precompiled heder to Not Using Precompiled Headers and remove stdafx.h and stdafx.cpp
hey Thomas I set it to not using precompiled headers and removed stdafx.h

code still gives me an error which is crazy,

how do I remove stdafx.cpp?

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# include <stdlib.h>
# include <WinSock2.h>
# include <iostream>
# include <Windows.h>
# pragma comment(lib,"ws2_32.lib")
using namespace std;

int main()
{

	cout << "hello" << endl;
	system("pause");
    return 0;
}
Hi Thomas I deleted stdafx.cpp and Source.cpp from the project and it now seems to build and compile

just wondering what is going on how come I needed to do all that just to get a simple project to compile other IDE's such as eclipse and C::B don't seem to need any of that?

thanks
The project templates is VS are more for professionals and not so much for beginners.
All this stdafx stuff with pre-compiled headers makes only sense for big projects, but are a pain in the neck for small test apps.
I usually start with an empty project and add a main.cpp and paste my own code.
Topic archived. No new replies allowed.