如何输出_tmain中的argv[]
今天想用VS2005中的VC++做一个WIN32控制台(console)下的应用程序,向导程序默认给出的是以下内容:
9
想当然,很好,很容易。试试列出命令的参数:
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
2
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
3
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
4
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
5
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
6
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/2f88ce130b654eb5dc6788e02dbcfc90.gif)
7
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
8
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
9
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
10
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/0ac3a2d53663ec01c7f7225264eeefae.gif)
11
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
运行结果竟然是这样的:
1 003A5210D:/MyData/CSharp/Projects/test/Debug>test
“003A5210”是什么值?一开始就弄不懂了。
如果把_tmain函数变为:
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
2
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/2f88ce130b654eb5dc6788e02dbcfc90.gif)
3
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
4
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
5
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
6
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/0ac3a2d53663ec01c7f7225264eeefae.gif)
7
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
运行结果正常:
D:/MyData/CSharp/Projects/test/Debug>test 1 d:/MyData/CSharp/Projects/test/Debug/test.exe
头大了。最后分别对两个函数运用断点中的反汇编看看,发现原来**argv竟然是wchar_t**,再翻弄了一下_TCHAR的声明:typedef wchar_t _TCHAR;
一切明白了。要输出这个_TCHAR只能用cout的另一个版本:wcout。
为什么呢?原因很简单,因为他们都带了一个“w”在前面啊!
能正确输出_TCHAR* argv[]的版本:
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
2
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
3
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
4
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
5
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
6
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/2f88ce130b654eb5dc6788e02dbcfc90.gif)
7
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
8
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
9
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
10
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/0ac3a2d53663ec01c7f7225264eeefae.gif)
11
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
给出一个网上对_tmain的一个有用的定义:
对于ANSI版本,"_tWinMain"就是"WinMain";对于UINCODE版本,"_tWinMain"就是"wWinMain"。
(比如这样的定义:)
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
2
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
3
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
4
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
5
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
6
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
7
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
所以,_tmain()不过是unicode版本的的main()
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
2
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
3
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/cbef093dcc044b2793832001e2365e43.gif)
4
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/2f88ce130b654eb5dc6788e02dbcfc90.gif)
5
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
6
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
7
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/df37983f39daa189b8c814e01a6a9011.gif)
8
![如何输出_tmain中的argv[] - xiaotot - 享受编码 如何输出_tmain中的argv[] - xiaotot - 享受编码](https://i-blog.csdnimg.cn/blog_migrate/0ac3a2d53663ec01c7f7225264eeefae.gif)