Page 1 of 1

How do I get rid of stdafx.h?

Posted: Sat Sep 26, 2009 7:08 am
by Pickzell
In Visual Studio 2008 is there a way to not have to include stdafx.h? I remember Marauder saying you could turn it off in the options but I don't know how.
VC++ confuses me, I miss dev-c++ :(

Re: How do I get rid of stdafx.h?

Posted: Sat Sep 26, 2009 8:10 am
by short
Pickzell wrote:In Visual Studio 2008 is there a way to not have to include stdafx.h? I remember Marauder saying you could turn it off in the options but I don't know how.
VC++ confuses me, I miss dev-c++ :(
Start a new project, and during the setup turn off the precompiled header. Choose "empty project" instead.

Re: How do I get rid of stdafx.h?

Posted: Sat Sep 26, 2009 8:52 am
by Pickzell
Thanks! A simple program like this would work

Code: Select all

int main()
{
   return 0;
}
But, I have another question...
I did this:

Code: Select all

#include <iostream>

int main()
{
   cout << "Hello World!\n";
   cin.get();
   return 0;

}
And now I'm WTF-ing
Image

Re: How do I get rid of stdafx.h?

Posted: Sat Sep 26, 2009 9:15 am
by Bludklok
You forgot to include the namespace...

Code: Select all

#include <iostream>
using namespace std;

int main()
{
     cout << "Hello world" << endl;
     return 0;
}

Re: How do I get rid of stdafx.h?

Posted: Sat Sep 26, 2009 9:18 am
by Xeno
I've not used Visual Studio with c++ but try adding:

Code: Select all

using namespace std;
or put std:: infront of the cout / cin

Code: Select all

#include <iostream>

int main()
{
   std::cout << "Hello World!\n";
   std::cin.get();
   return 0;

}
Edit: I was beaten to it :P

Re: How do I get rid of stdafx.h?

Posted: Sat Sep 26, 2009 9:48 am
by captjack
And yet one other option. Instead of using the entire std namespace, you could:

Code: Select all

#include <iostream>
using std::cout;
using std::endl;

int main()
{
     int i = 0;

     cout << "i = " << i << endl;
     return 0;
}
This would enable use of just cout and endl without the need for std::cout or std::endl. C++ is really flexible with namespaces.

Re: How do I get rid of stdafx.h?

Posted: Sat Sep 26, 2009 10:53 am
by Pickzell
/facepalm

I forgot to do the most basic thing.
Go me.