Cannot start any programs?

In C++ I open a new win32 console application, and then I input this:
#include <iostream>

int main()
{
std::cout <<"Welcome to C++!\n";

return 0;
}


When I press the play button it says that the project is out of date and asks if I would like to build it, it says this in the bottom space if I press yes:

1>------ Build started: Project: helloworld2, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>c:\program files\microsoft visual studio 9.0\vc\include\xlocnum(135) : error C2857: '#include' statement specified with the /Ycstdafx.h command-line option was not found in the source file
1>Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\helloworld2\helloworld2\Debug\BuildLog.htm"
1>helloworld2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

then it asks me if I would like to run last succesful build and if I press yes it says that the program cannot be run because the system file could not be specified. If I press no when it asks me if I want to build it, it goes straight to this. I don't know what to do. I am trying to learn programming with the Deitel How to learn C++ sixth edition.
Try writing system("pause"); on the line before the return 0;....otherwise the program worked fine on my compiler.
Also, depending on your compiler, you might need .h after iostream........ #include<iostream.h>
Visual Studio has a precompiled thing it does for you. There are two file stdafx.h and stdafx.cpp. You can ignore the cpp file, it has no code and just includes the header file. What you do need to be aware of is that all your cpp files have to include stdafx.h otherwise the compiler complains. The precompiled option can be switched off so you don't have to do it, its somewhere in the project properties, I can't remember where.

So, after all that try adding #include "stdafx.h" to you file.
I tried adding all of these seperately and in all combinations, and none of these helped. I don't think there is anything wrong with the code because I had a friend of mine run this on his computer, and it worked, and he downloaded the same version of C++ off microsoft that I did.
hope this will help you
#include <iostream>
#include<conio>
int main()
{
std::cout <<"Welcome to C++!\n";
getch();
return 0;
}

Topic archived. No new replies allowed.