Headers are driving me crazy.

I have no idea why this isn't working, although I am new to this.

#include <iostream>
#include <stdafx>
using namespace std;


void main()

{


double a;

cout<< "Enter your number" << endl << "HERE:";
cin>>a;
cout<< "Your number is:" << a;

_getch();


}






This is the error message:



1>------ Build started: Project: Variables, Configuration: Debug Win32 ------
1> Variables.cpp
1>Variables.cpp(1): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>Variables.cpp(20): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Help would be appreciated. Thank you in advance.
#include <iostream>

void main(){
cout<<"Test"<<endl;
system("puase")
}



Even something like this won't work and I have no idea why. This is the error:

1>------ Build started: Project: simple program, Configuration: Debug Win32 ------
1> stdafx.cpp
1> AssemblyInfo.cpp
1> simple program.cpp
1>simple program.cpp(1): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>simple program.cpp(7): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
there is no need to include <stdafx> in that program, everything you are doing is in the standard iostream. second, use int main not void main. void main makes it harder to debug and can cause problems later when you are making programs interact with each other. all you need is

#include <iostream>
//using namespace std if you want
int main(){
double d;
std::cout << "Enter your number"<< '\n' << "HERE:";
std::cin >> d;
std::cout << "Your number is " << d;
std::cin.ignore();
return 0;
}
Thank you but for some reason even when I copy and paste your code it still doesn't work. I think I might be using the wrong project. It is CLR Console Application.


This is the error:


1>------ Build started: Project: simple program, Configuration: Debug Win32 ------
1> simple program.cpp
1>simple program.cpp(1): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>simple program.cpp(10): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


This is the code:


#include <iostream>
int main(){
double d;
std::cout << "Enter your number"<< '\n' << "HERE:";
std::cin >> d;
std::cout << "Your number is " << d;
std::cin.ignore();
return 0;
}
Just turn off the use of precompiled headers.

See: http://www.cplusplus.com/forum/beginner/27835/#msg149337
You're a life saver. Thanks
Topic archived. No new replies allowed.