0

Okay. So I've got a simple question. If I ask it in the wrong place, please correct me. What I want to ask is, why Visual Studio gives me this:

#include "stdafx.h"


int main()
{
    return 0;
}

everytime I create a new project? (I know I can select Empty Project, and add mine .cpp file by myself, but I'm just curious. It says #include <stdio.h> and #include <tchar.h>. So what is it for? Are you all using it or something?

And P.S - why there is no (int argc, char** argv) in main declaration? (on my coding course in college I've learned that there may be _tmain(int argc, _TCHAR* argv), when creating something in VS)

minecraftplayer1234
  • 2,127
  • 4
  • 27
  • 57
  • 4
    This is a Visual Studio oddity. It supports their precompiled headers. Parameters to `main` are optional--you can add them if needed, or omit them if you're not using them. `_tmain` as the program entry point is also a Microsoft oddity, not part of standard C++. – Jerry Coffin Mar 02 '16 at 19:41
  • 1
    you can remove `stdafx.h` and after that you got to disable precompiled headers -> http://stackoverflow.com/questions/7261707/how-to-avoid-precompiled-headers – Angelus Mortis Mar 02 '16 at 19:51

3 Answers3

3

Okay. So I've got a simple question. If I ask it in the wrong place, please correct me. What I want to ask is, why Visual Studio gives me this: ...

Well, it depends a bit on the project type you've been choosing from the wizard. Looks like the standard template for a console project.

#include "stdafx.h"

is prepended for any type of translation unit by the wizard. It supports the precompiled header optimizaton mechanism.


why there is no (int argc, char** argv) in main declaration?

Because the template provides the minimum for a valid main() entry routine definition.

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
2

When creating a new Win32 project, Visual Studio automatically adds a precompiled header "stdafx.h" to your project, even if you unchecked the 'Empty Project' checkbox.

If you want to disable this, go to your project configuration properties -> C/C++ -> Precompiled Headers and select 'Not Using Precompiled Headers'.

Working with precompiled headers see: https://stackoverflow.com/a/4726838.

And P.S. look at -> https://stackoverflow.com/a/4207223

Community
  • 1
  • 1
Kevin
  • 506
  • 6
  • 13
2

The precompiled header is for speeding up compile times by compiling the contents of your most frequently included headers only once and then reusing the compile results. You can change its name if you want.

Myrle Krantz
  • 136
  • 1
  • 3