Not sure why I can't compile...

Jun 29, 2011 at 12:39am
I made a simple program, and it won't compile. Here's the program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int returnthis (int a; int b;) {
	return a + b;
}

int main ()
{
	int returnedint, a, b;
	cout << "Enter a number: \n";
	cin >> a;
		cout << "Enter a number: \n";
		cin >> b;
returnedint = returnthis(a,b);

		cout << "Result: " << returnedint;
		return;
}


When I try to build in MS visual C++ express, I get the following errors:

1>MyFirstCplusplusFunction.cpp(2): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>MyFirstCplusplusFunction.cpp(21): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?

Can someone help, please?
Last edited on Jun 29, 2011 at 12:40am
Jun 29, 2011 at 1:19am
You need to disable the 'using compiled headers' option. In the future, just make an empty project to avoid that.
Jun 29, 2011 at 10:53am
Oh thank you, I did not know you could do that. I eventually followed the compilers reccomendation in the error window, and added "stdafx.h" which fixed my problem.
Topic archived. No new replies allowed.