473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

understanding main() and _tmain

//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

Nov 16 '07 #1
2 4014
_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
<to********@googlemail.comwrote in message
news:0a**********************************@v4g2000h sf.googlegroups.com...
//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

Nov 16 '07 #2
On 16 Nov, 14:44, "Cholo Lennon" <chololen...@hotmail.comwrote:
_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
Nov 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter | last post by:
Hi, I have the following (simplified for posting) main program: ----------------------------------------- int _tmain( int argc, _TCHAR* argv ) { //Create socket listener
7
by: Howard | last post by:
Hi all, with all the posts I see that have "void main()", and all the resulting corrections, I have to wonder...is there a commonly-used IDE out there that generates "void main()" by default...
7
by: Bernd Danberg | last post by:
Hi, I have a real strange problem with the command line arguments given to the main-function and together with using std::string: #include <string> int _tmain(int argc, _TCHAR* argv) {...
2
by: O.R.Senthil Kumaran | last post by:
Hi list: Following is a piece of code: main(int argc, char** argv) { int rc, result; struct passwd *uidpwent; /* init resources */
26
by: Bail | last post by:
I will have a exam on the oncoming friday, my professor told us that it will base upon this program. i am having troubles understanding this program, for example what if i want to add all the...
7
by: Buck Rogers | last post by:
Hi all! Newbie here. Below is an example from Teach Yourself C in 21 Days. My apologies if it is a bit long. What I don't understand is how the "get_data" function can call the...
5
by: wishbone34 | last post by:
I've gotten help writing out these functions, and i know what they each do individually, but i can't figure out where to start in my main program, i want to enter a string of numbers and...
2
by: subramanian100in | last post by:
Is my following understanding correct ? Data abstraction means providing the interface - that is, the set of functions that can be called by the user of a class. Information hiding means...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.