#include "stdafx.h" needs to appear before #include <fstream>? 
Author Message
 #include "stdafx.h" needs to appear before #include <fstream>?

Hi,

I have created a console application as listed below but it doesn't
seem to compile unless I move the stdafx.h include line above the
fstream include line.  Any ideas why?  This seems really strange to me
since there is nothing in the stdafx.h file except what I have listed
below.  As you can see I have not change it in any way from the way
the file was generated.

Any help would be most appreciated.  
Thanks in advance.

GOGOMAN

// -------------------------------------------
// Main.cpp file
#include <fstream>
#include "stdafx.h"
using namespace std;

int main( int argc, char **argv )
{
  fstream inputFile;
  return 0;

Quote:
}

// -------------------------------------------
// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//

#if
!defined(AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_)
#define AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.

#endif //
!defined(AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_)



Fri, 04 May 2001 03:00:00 GMT  
 #include "stdafx.h" needs to appear before #include <fstream>?
What compiler error messages are you getting when you don't have stdafx.h
included first?

--
J. Keith Wedinger
Technical Specialist - The Limited, Inc.

http://www.serve.com/uccats

Quote:

>Hi,

>I have created a console application as listed below but it doesn't
>seem to compile unless I move the stdafx.h include line above the
>fstream include line.  Any ideas why?  This seems really strange to me
>since there is nothing in the stdafx.h file except what I have listed
>below.  As you can see I have not change it in any way from the way
>the file was generated.

>Any help would be most appreciated.
>Thanks in advance.

>GOGOMAN

>// -------------------------------------------
>// Main.cpp file
>#include <fstream>
>#include "stdafx.h"
>using namespace std;

>int main( int argc, char **argv )
>{
>  fstream inputFile;
>  return 0;
>}

>// -------------------------------------------
>// stdafx.h : include file for standard system include files,
>//  or project specific include files that are used frequently, but
>//      are changed infrequently
>//

>#if
>!defined(AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_)
>#define AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_

>#if _MSC_VER > 1000
>#pragma once
>#endif // _MSC_VER > 1000

>// TODO: reference additional headers your program requires here

>//{{AFX_INSERT_LOCATION}}
>// Microsoft Visual C++ will insert additional declarations
>immediately before the previous line.

>#endif //
>!defined(AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_)



Fri, 04 May 2001 03:00:00 GMT  
 #include "stdafx.h" needs to appear before #include <fstream>?
That's standard. Nothing in front of the stdafx include is compiled.
--
Dan Evens
(Standard disclaimers etc. No spam please.)


Quote:
> Hi,

> I have created a console application as listed below but it doesn't
> seem to compile unless I move the stdafx.h include line above the
> fstream include line.  Any ideas why?



Fri, 04 May 2001 03:00:00 GMT  
 #include "stdafx.h" needs to appear before #include <fstream>?
Two words:  precompiled headers

The compiler, in order to improve build speed, uses the "stdafx.h" as a
marker to do it's stuff (simplistically speaking) with precompiled headers.
Anything (and I do mean anything) before that is ignored.

If you don't like this behavior, simply turn off precompiled headers for
that project, and it won't do that anymore.

Of course, builds will now take longer.

HTH

--
Reginald Blue                   | Opinions expressed here do not
Natural Language Understanding  | necessarily represent those of
Unisys Corporation              | my employer.
                                |-------------------------------
                                | My email address is wrong, you

Quote:

>Hi,

>I have created a console application as listed below but it doesn't
>seem to compile unless I move the stdafx.h include line above the
>fstream include line.  Any ideas why?  This seems really strange to me
>since there is nothing in the stdafx.h file except what I have listed
>below.  As you can see I have not change it in any way from the way
>the file was generated.

>Any help would be most appreciated.
>Thanks in advance.

>GOGOMAN

>// -------------------------------------------
>// Main.cpp file
>#include <fstream>
>#include "stdafx.h"
>using namespace std;

>int main( int argc, char **argv )
>{
>  fstream inputFile;
>  return 0;
>}

>// -------------------------------------------
>// stdafx.h : include file for standard system include files,
>//  or project specific include files that are used frequently, but
>//      are changed infrequently
>//

>#if
>!defined(AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_)
>#define AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_

>#if _MSC_VER > 1000
>#pragma once
>#endif // _MSC_VER > 1000

>// TODO: reference additional headers your program requires here

>//{{AFX_INSERT_LOCATION}}
>// Microsoft Visual C++ will insert additional declarations
>immediately before the previous line.

>#endif //
>!defined(AFX_STDAFX_H__9208CD7B_6BA8_11D2_B70A_00104B6E2303__INCLUDED_)



Fri, 04 May 2001 03:00:00 GMT  
 #include "stdafx.h" needs to appear before #include <fstream>?
Thats right. Let me elaborate:

You know, in a typical project each C++ file will include several .h files.
The complier has to read all these .h files and parse. This will involve a
lot of build. One solution to this problem is pre-compliled headers. That
is if you happen to include the same set of header files in more than one
C++ file, the complier can pre-compile these header files and re-use them.
In all AppWizard generated code, these common header files are included in
stdafx.h which in turn is included in all C++ files. There is a special
file stdafx.cpp that has a single line:

#include "stdafx.h".

The build process is such that stdafx.cpp is compiled first. When this
happens, the comiler stores the pre-comipled information in a .ph file. In
all other C++ files, which are comiled later, the compiler skips upto
'#include "stdafx.h"' and uses the information in the .ph file. This
enhances the speed.

Hope this is useful



Quote:
> Two words:  precompiled headers



Sat, 05 May 2001 03:00:00 GMT  
 #include "stdafx.h" needs to appear before #include <fstream>?
The reason for this is the se of precompiled headers.
See the message from Reginald Blue for more information.

Dennis

Quote:

>That's standard. Nothing in front of the stdafx include is compiled.
>--
>Dan Evens
>(Standard disclaimers etc. No spam please.)


>> Hi,

>> I have created a console application as listed below but it doesn't
>> seem to compile unless I move the stdafx.h include line above the
>> fstream include line.  Any ideas why?



Sat, 05 May 2001 03:00:00 GMT  
 #include "stdafx.h" needs to appear before #include <fstream>?

Quote:

>Hi,

>I have created a console application as listed below but it doesn't
>seem to compile unless I move the stdafx.h include line above the
>fstream include line.  Any ideas why?  This seems really strange to me
>since there is nothing in the stdafx.h file except what I have listed
>below.  As you can see I have not change it in any way from the way
>the file was generated.

This is almost certainly because of your use of precompiled headers.  Look
for "precompiled headers" in the online references for a detailed
explanation.

Thanks,
Andrew



Mon, 14 May 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. #include "stdafx.h" needs to appear before #include <fstream>?

2. pronounce "#include <stdio.h>"

3. error in #include "stdafx.h"

4. #include "stdafx.h"

5. #include "stdafx.h"

6. #include <stdafx.h>

7. #include <stdafx.h>

8. Problem error at #include <stdafx.h>

9. #include <stdafx.h>

10. #include <stdafx.h>

11. #include <stdafx.h>

12. #include "foo" vs #include <foo>

 

 
Powered by phpBB® Forum Software