Can someone explain "int _tmain(int argc, _TCHAR* argv[])"

So normally I use Dev C++ which is a pretty straightforward and easy-to-use IDE. However, I tried downloading Visual Studio to try something new and I feel like it's overly complicated.

Every new C++ project starts out with this stuff:

1
2
3
4
5
6
7
8
#include "stdafx.h"


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


So, I can guess that "stdafx.h" is some header file with important stuff in it pertaining to Visual Studio only.

What I don't understand is the "_tmain" function. I also don't understand what its arguments are for. Is this just the same as "int main()" but for Visual Studio? What am I supposed to do with it?

You can safely ignore them most likely. However if you were to write a program that accepts arguments from the command line you may want to read this:
http://www.cs.hmc.edu/~geoff/classes/hmc.cs070.200401/notes/command-args.html
Its a really quick read on what these arguments mean.
I am assuming that _TCHAR is a replacement for the regular char, and _tmain is probably a replacement for the regular main.
I recommend you create empty projects in VS unless you have a reason not to.
closed account (zb0S216C)
"_tmain( )" is an extension of Microsoft's C++ compiler and therefore, is non-standard. Considering that you've come from Dev-C++, I recommend that you use either Orwell Dev-C++[1] (the modern version of the old Dev-C++), Code-Lite[2] or Code::Blocks[3].

In my opinion, the change between Dev-C++ and Visual C++ is too big of a transition for you which is causing you confusion. With Code::Blocks or Orwell, the interface is far more friendly and easier to get-to-grips with.

[1]Orwell Dev-C++: http://orwelldevcpp.blogspot.co.uk/
[2]Code-Lite: http://codelite.org/
[3]Code::Blocks: http://www.codeblocks.org/downloads

Wazzak
> What am I supposed to do with it?

Delete it. And in its place write either
1
2
3
4
int main()
{
    // ...
}

or
1
2
3
4
int main( int argc, char* argv[] )
{
    // ...
}


> In my opinion, the change between Dev-C++ and Visual C++ is too big of a transition for you which is causing you confusion.

Not really. Any IDE is confusing when one encounters it for the first time. It takes a small amount of time to get used to an IDE.
Every new C++ project starts out with this stuff:


No, they don't. I generally begin with an "Empty Project" which has none of that cruft inserted. If you do that, you do need to select the console subsystem in the linker settings to get the behavior most people prefer when running a program from within the IDE (ie. make the program pause at the end of execution.)

Alternately you can select a "Win32 Console Application" and check the appropriate boxes in the wizard to make sure the boiler plate isn't written for you. (Precompiled headers disabled, empty project selected.)
Topic archived. No new replies allowed.