vs2005 int _tmain(int argc, _TCH…
2013-10-23 23:37
246 查看
用VS2005中的VC++做一个WIN32控制台(console)下的应用程序,向导程序默认给出的是以下内容:
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#include "stdafx.h"
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
int _tmain(int argc, _TCHAR* argv[])
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
{
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
return 0;
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
8
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
}
想当然,很好,很容易。试试列出命令的参数:
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#include "stdafx.h"
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
using namespace std; //必须在stdafx.h增加#include <iostream>
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
int _tmain(int argc, _TCHAR* argv[])
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
{
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
cout << argc <<endl;
8
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
cout << argv[0] <<endl;
9
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
return 0;
10
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
}
11
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
运行结果竟然是这样的:
“003A5210”是什么值?一开始就弄不懂了。
如果把_tmain函数变为:
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
int main(int argc, char* argv[])
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
{
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
cout << argc <<endl;
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
cout << argv[0] <<endl;
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
return 0;
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
}
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
运行结果正常:
头大了。最后分别对两个函数运用断点中的反汇编看看,发现原来**argv竟然是wchar_t**,再翻弄了一下_TCHAR的声明:typedef wchar_t
_TCHAR;
一切明白了。要输出这个_TCHAR只能用cout的另一个版本:wcout。
为什么呢?原因很简单,因为他们都带了一个“w”在前面啊!
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
能正确输出_TCHAR*
argv[]的版本:
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#include "stdafx.h"
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
using namespace std;
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
int _tmain(int argc, _TCHAR* argv[])
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
{
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
wcout << argc <<endl;
8
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
wcout << argv[0] <<endl;
9
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
return 0;
10
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
}
11
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
给出一个网上对_tmain的一个有用的定义:
对于ANSI版本,"_tWinMain"就是"WinMain";对于UINCODE版本,"_tWinMain"就是"wWinMain"。
(比如这样的定义:)
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#ifdef _UNICODE
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#define _tmain wmain
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#define _tWinMain wWinMain
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#else
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#define _tmain main
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#define _tWinMain WinMain
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#endif
所以,_tmain()不过是unicode版本的的main()
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#include "stdafx.h"
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
int _tmain(int argc, _TCHAR* argv[])
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
{
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
return 0;
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
8
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
}
想当然,很好,很容易。试试列出命令的参数:
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#include "stdafx.h"
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
using namespace std; //必须在stdafx.h增加#include <iostream>
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
int _tmain(int argc, _TCHAR* argv[])
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
{
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
cout << argc <<endl;
8
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
cout << argv[0] <<endl;
9
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
return 0;
10
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
}
11
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
运行结果竟然是这样的:
D:\MyData\CSharp\Projects\test\Debug>test 1 003A5210 |
如果把_tmain函数变为:
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
int main(int argc, char* argv[])
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
{
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
cout << argc <<endl;
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
cout << argv[0] <<endl;
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
return 0;
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
}
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
运行结果正常:
D:\MyData\CSharp\Projects\test\Debug>test 1 d:\MyData\CSharp\Projects\test\Debug\test.exe |
_TCHAR;
一切明白了。要输出这个_TCHAR只能用cout的另一个版本:wcout。
为什么呢?原因很简单,因为他们都带了一个“w”在前面啊!
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
能正确输出_TCHAR*
argv[]的版本:
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#include "stdafx.h"
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
using namespace std;
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
int _tmain(int argc, _TCHAR* argv[])
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
{
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
wcout << argc <<endl;
8
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
wcout << argv[0] <<endl;
9
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
return 0;
10
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
}
11
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
给出一个网上对_tmain的一个有用的定义:
对于ANSI版本,"_tWinMain"就是"WinMain";对于UINCODE版本,"_tWinMain"就是"wWinMain"。
(比如这样的定义:)
1
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#ifdef _UNICODE
2
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#define _tmain wmain
3
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#define _tWinMain wWinMain
4
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#else
5
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#define _tmain main
6
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#define _tWinMain WinMain
7
![](http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif)
#endif
所以,_tmain()不过是unicode版本的的main()
相关文章推荐
- 主函数main中变量(int&nbsp;argc…
- 主函数main中变量(int&nbsp;argc…
- int main(int argc,char…
- int*&nbsp;与&nbsp;int&amp;
- (转)ns2代码(int&nbsp;agrc,const&nbsp;cha…
- 转-int ,long , lo…
- 捕获一个int变量, 判断是否…
- static int
- xcode 4 使用指南系列2-Int…
- *(int *)a
- INT 21H指令大全
- mysql&nbsp;int(3)与int(11)的区…
- ch09_ex25&nbsp;int&nbsp;Search(S…
- int char* string …
- unsigned int的 注意事项
- mysql&nbsp;中int和integer有什么区别
- (转)关于主函数:int&nbsp;main(int&amp;nb…
- Android中 int 和 String 互…
- 维基百科里 的intj &nbs…
- OERR: ORA-3137 "TTC protocol int…