problems with "stdafx.h"

Posted on 2004-04-02
Medium Priority
Last Modified: 2008-02-01

I'm developing cross-platform application using C++.
I want to include "stdafx.h" header file only when compiling in Microsoft Visual C++.


#if defined (_MSC_VER)
#include "stdafx.h"

int main()

When compiling using Microsoft Visual C++, I get:

"fatal error C1019: unexpected #endif"

What should I do for condition including "stdafx.h" ???
Question by:NetwrkGuru
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Expert Comment

ID: 10740116
you should use
#ifdef _MSC_VER
#include "stdafx.h"
LVL 16

Expert Comment

ID: 10740125
In fact it's the same :)
I think you have some unmatch #endif in your stdafx.h
Could you post it?
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10740179
What's in your stdafx.h? It's possible that the unmatched #if is in one of your include files, and not the .cpp file.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 10740603
stdafx.h contains standart stuff after creating standart Win32 console application using VC++ wizard.
LVL 16

Expert Comment

ID: 10740625
please post it for check in order to get more help.
LVL 15

Accepted Solution

lakshman_ce earned 200 total points
ID: 10740982
In Visual studio,
select your proeject->go to settings->C++->precompiled headers (select from drop down)
give the option Not using precompiled headers. This will enable you to compile in VC++ without stdafx.h and also the same code can be used for compiling on AIX or anywhere else.


Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question