-3

When creating a new C++ Windows Application in Visual Studio 2017, I am always given an stdafx.cpp file, as well as stdafx.h and targetver.h files. I am taking an Intro Programming class and the instructor thoroughly disapproves of these files being included in our projects. I am using a Mac with BootCamp to run this compiler properly, and I am able to write my code and run it fine - but I need to get rid of these extraneous files that are included with my project.

My professor's suggestion was to instead create an Empty Project when initially making the project, but this must leave out some type of necessary libraries/headers because my same code will misbehave with functions like "cout". (builds fine).

Put simply, how can I create a new project that is empty besides my cpp file, and behaves as normal?

M.M
  • 138,810
  • 21
  • 208
  • 365
frejil
  • 21
  • 4
  • What's with all the hate for `stdafx.h`? It's supposed to help compile times. – tadman Sep 20 '17 at 21:50
  • 3
    Your professor is right. Make an empty project, then create a source file manually. It's easier than changing all the settings to remove precompiled headers – Justin Sep 20 '17 at 21:50
  • 1
    @tadman not if you're trying to compile the same code on a different compiler – M.M Sep 20 '17 at 21:50
  • @tadman It hardly does, and it causes lots of problems when following standard C++ texts. I have an old tutorial here that addresses this: https://latedev.wordpress.com/2012/04/13/howto-create-your-first-project-in-visual-c/ –  Sep 20 '17 at 21:51
  • If you're creating a cross-platform application, sure, but this is when creating a *Windows Application* which is by definition not going to be cross-platform. – tadman Sep 20 '17 at 21:51
  • 2
    Precompiled headers can decrease compilation times significantly, but it strongly depends on what you put in them and how you configure them. Done wrong, it's easy to *increase* compilation times significantly. For clean portability, it can be a better idea to use CMake and Cotire and never manually have a `#include "stdafx.h"`. – Justin Sep 20 '17 at 21:54
  • A portable program does not need that header. Just create an empty project and only include what you need. – Jesper Juhl Sep 20 '17 at 21:58
  • @Justin I try to do this, and I create my source file manually and everything seems to be fine. But when running a simple program it crashes when trying to output something, randomly. For example, the program I'm writing takes input, does a calculation and outputs a number. Right now, I can prompt the user to input something (using cout and cin) but then when I try to just output something (without taking anything as an input directly after) the program displays something then quickly crashes. – frejil Sep 20 '17 at 22:01
  • 2
    @frejil You just need to figure out what is wrong with out program, maybe debug it. Precompiled headers have nothing to do with it. – user7860670 Sep 20 '17 at 22:03
  • @VTT precompiled headers are entirely my problem. If I paste the exact same code into a program created with these headers it behaves as normal. – frejil Sep 20 '17 at 22:04
  • @NeilButterworth We are getting somewhere! This is exactly my problem. On the lab computers in my class, the process of creating a program goes exactly like that, and I can check empty project and all. However, on my computer I am not given that wizard window with the options of "Next" and "Finish" it simply creates the project with no further prompts. That is why my professor suggested creating an "Empty project" instead of a "Windows Console Application" – frejil Sep 20 '17 at 22:06
  • @frejil Then you need a [mcve]. It's definitely not *just* precompiled headers. – Justin Sep 20 '17 at 22:06
  • @Justin my code is not the problem here, I can assure you of that. It is likely a compiler setting that I did or did not check. I don't know if it's against the rules, but if you shoot me your email I can further clarify the problem with pictures. – frejil Sep 20 '17 at 22:08
  • 1
    `cout << "enter height" << cin` won't even compile, there is no << operator for output stream that takes input stream. – user7860670 Sep 20 '17 at 22:08
  • @Justin With all due respect, how exactly would I provide an example of something that doesn't involve code? My issue lies within my compiler. I could copy and paste one of the thousand "Hello World" examples from the internet into my project and it would not run properly. Not because of a code error, but because of an improper setting. Your responses are either going right over my head or you're not reading my question. – frejil Sep 20 '17 at 22:13
  • @frejil I guarantee you that this is not a compiler bug. How you can provide an example is to supply a source file, the stdafx.h, and how you set up the project (step by step if necessary) – Justin Sep 20 '17 at 22:14
  • 1
    Here is the algorithm for you: 1) copy and paste one "Hello World" example code into your cpp file 2) build it (it's ok if it fails) 3) copy and paste entire content of you cpp file into question 4) copy and paste entire build log into your question – user7860670 Sep 20 '17 at 22:15
  • 1
    @frejil For someone who just started out programming, your absolute conviction that it's impossible for your code to be wrong is.. entertaining. No seasoned programmer would ever make such an assumption. – Voo Sep 20 '17 at 22:16

2 Answers2

2

You can create a new project and disable use of of precompiled headers and please also select Empty Project while creating. If you don't intend to create a new project file, you can do this in the existing project file.To do this, do the following -

Select your project, use the "Project -> Properties" menu and go to the "Configuration Properties -> C/C++ -> Precompiled Headers" section, then change the "Precompiled Header" setting to "Not Using Precompiled Headers" option.

Naseef Chowdhury
  • 2,357
  • 3
  • 28
  • 52
1

when you create a project with visual studio ,you'll have the option "use pre compiled headers" which you can disable !

NB Just discovered that the new update (15.3.5) of vs2017 has changed the creation of projects a little and seems to offer this only when choosing Windows desktop wizard !

engf-010
  • 3,980
  • 1
  • 14
  • 25