Hello,
I've been using Code Blocks as an IDE for a while and decided to switch to VS2010 Professional as I had obtained it throuh Dreamspark. Anyway, I'm terribly confused at the files it gives me for a standard Win32 Console App for C++. Usually, I'm used to seeing:

#include <iostream>
using namespace std;
int main() {
return 0;
}

But in VS, when I load up a basic project, I see this:

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

I have no idea what's going on! Also, it has given me two header files "stdafx.h" and "targetver.h", as well as two source files "projectname.cpp" and "stdafx.cpp". Normally, I'm used to seeing only one of each or only the source file, so yeah, I don't exaclty know where to start, any help would be much appreciated!
Thanks!
Carpetfizz

Recommended Answers

All 5 Replies

If you want to write standard C++, I'd strongly recommend only using an empty project. Then you don't have to deal with Microsoft's precompiled headers (stdafx.h) or any of their character width agnostic types.

The _T stuff is supposed to use the correct width character type depending on whether a macro switch for Unicode is defined or not, where it's just char when undefined and wchar_t when defined. It's not a bad idea, but you lock yourself into the Microsoft CRT libraries by using it.

VC++ defaults to using precompiled headers, which means that it will preprocess all the header files once and use that preprocessed file for all the *.cpp files in the project. stdafx.h is the header file which contains all the other include files that are usd for this purpose. So the first thing that must appear in all *.cpp files of the project is stdafx.h. If a *.cpp file need other includes they must appear after stdafx.h. This might seem a little complicated, but for large projects it can greatly speed up compiling all those *.cpp files. You have the option to turn off precompiled header files if you want to either when you create the project or later by changing one of the project properties. Once you turn precompiled headers off you can delete and remove from the project stdafx.h and stdafx.cpp if you want to.

_tmain and TCHAR are actually macros which allow your program to be easily compiled for UNICODE or not. VC++ defaults to UNICODE, which affects all the strings in the program. You can turn that off in one of the project properties. UNICODE is a computer standard way to represent languages whose alphabet requires multiple bytes of memory. For example each letter of the English alphabet consumes one byte of memory, but in Chinese a letter might need several bytes because they are graphic characters. If you want your program to be in Engligh only (or one of the other western languages) then turn UNICODE off.

Thanks much for the replies! Also, for some reason I'm finding it difficult to find the "empty" project option...

It's in the Visual C++ -> General project templates.

Got it, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.