How do I get rid of stdafx.h?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Pickzell
Chaos Rift Junior
Chaos Rift Junior
Posts: 233
Joined: Sat May 16, 2009 10:21 am

How do I get rid of stdafx.h?

Post 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++ :(
I'm an altogether bad-natured Cupid.
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

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

Post 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.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
Pickzell
Chaos Rift Junior
Chaos Rift Junior
Posts: 233
Joined: Sat May 16, 2009 10:21 am

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

Post 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
I'm an altogether bad-natured Cupid.
User avatar
Bludklok
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Tue Apr 14, 2009 1:31 am
Current Project: EnigmaCore
Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
Programming Language of Choice: C++
Location: New Jersey
Contact:

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

Post by Bludklok »

You forgot to include the namespace...

Code: Select all

#include <iostream>
using namespace std;

int main()
{
     cout << "Hello world" << endl;
     return 0;
}
Youtube
Website
Current project: Enigma Core
Xeno
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 12
Joined: Fri Jun 05, 2009 5:03 am

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

Post 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
User avatar
captjack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 50
Joined: Fri Sep 18, 2009 4:23 pm
Current Project: engine framework
Favorite Gaming Platforms: PC, XBox 360, PS3
Programming Language of Choice: C, C++
Location: Northern Virginia

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

Post 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.
User avatar
Pickzell
Chaos Rift Junior
Chaos Rift Junior
Posts: 233
Joined: Sat May 16, 2009 10:21 am

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

Post by Pickzell »

/facepalm

I forgot to do the most basic thing.
Go me.
I'm an altogether bad-natured Cupid.
Post Reply