Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2007

Tip: Looking for answers? Try searching our database.

understanding main() and _tmain

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tonyjeffs2@googlemail.com - 16 Nov 2007 13:44 GMT
//int _tmain(int argc, _TCHAR* argv[])        // main for windows
int main(int argc, char *argv[])                   // ... or main

{
    cout <<argv[0]<<endl;
    return 0;
}

//run at command line: test.exe cat dog

With  main the output is "test.exe"  which I'd expect,
but a similar program using _ tmain outputs a number which I think is
the address of the 't' in test.exe. What is the logic behind this -
what's happening?

Thanks

Tony
Cholo Lennon - 16 Nov 2007 14:43 GMT
_tmain is a macro that expand to main o wmain according to _UNICODE macro. In
VC2005, By default , a program is unicode enabled (UNICODE and _UNICODE defined)
so your _tmain macro expands to wmain (not main) and _TCHAR expands to wchar_t.
The problem is that you are using  'cout'  (which is prepared to work with
single wide strings) with a double wide string.

// This should work
#include <iostream>
#include <tchar.h>

#ifdef _UNICODE
#define _tcout   wcout
#else
#define _tcout   cout
#endif

using namespace std;

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

Regards

--
Cholo Lennon
Bs.As.
ARG

> //int _tmain(int argc, _TCHAR* argv[])        // main for windows
> int main(int argc, char *argv[])                   // ... or main
[quoted text clipped - 14 lines]
>
> Tony
tonyjeffs2@googlemail.com - 16 Nov 2007 18:12 GMT
> _tmain is a macro that expand to main o wmain according to _UNICODE macro. In
> VC2005, By default , a program is unicode enabled (UNICODE and _UNICODE defined)
> so your _tmain macro expands to wmain (not main) and _TCHAR expands to wchar_t.
> The problem is that you are using  'cout'  (which is prepared to work with
> single wide strings) with a double wide string.
<....>

Thank you - I understand that!
Tony

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.