0

i just started learning c++ lately and i am using visual studio 2015. But i have to manually remove the #include stdafx.h in my cpp file before upload it to the test server for my class, or it just sends back an error like this:the error from test server

I would like to know why this issue is happening. My guess is that this thing is exclusive to windows and x86 based OS? Any help would be appreciated. :D

2 Answers2

1

stdafx.h is the default name of a precompiled header for a Visual Studio project. However, you can certainly have a file named this on other environments. Note that the Visual Studio compiler processes this header slightly differently than it does other headers, if it is specified as the precompiled header in your project's property pages (C/C++ -> Precompiled Headers - see here for more details). For example, multiple includes of this file with different preprocessor defines will be ignored when it is the precompiled header (which isn't that common, but something to be aware of).

If you want to make portability to non-Visual Studio environment easier, it's usually easier to disable precompiled headers in your Visual Studio project. If you continue to use the stdafx.h file in your code, you will obviously need to upload it to your test compilation server, and may need to modify it and/or its inclusion into your code.

MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
  • While stdafx.h is "just another header", as I said in the answer, it's not necessarily true that a Visual Studio project setup with stdafx.h as the precompiled header will compile on another build system, as the way VS processes the PCH is slightly different than other headers. – MuertoExcobito Feb 03 '17 at 14:18
  • No, even without platform specific stuff, it still _might_ not work, as I said in my answer. The PCH is applied to every file that includes it, but is only created for once. You could have (for example) different preprocessor #defines specified before including it in different source files, which would normally change behavior within stdafx.h, but, if it's the PCH, they will be whatever they were when the PCH is created. Whereas, it isn't the PCH, the differences would be applied. – MuertoExcobito Feb 03 '17 at 15:43
1

You'll need to upload all your sources. stdafx.h isn't special in that regard. Of course, if your course restricts you to one .cpp upload, then you can't use stdafx.h for that course

MSalters
  • 173,980
  • 10
  • 155
  • 350