vs下c++中main _tmain以及控制台程序结束后不出现press any key to continue问题

来源:互联网 发布:qq音乐三巨头知乎 编辑:程序博客网 时间:2024/05/18 10:24

视频教程在VC6中编译运行。我的电脑装VC6有问题,所以安装了vs2003。结果发现很多问题。

新建完后出来这么一段:

#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{

return 0;
}

在下边写main()提示不能重载。

问百度,收藏下给用得着的人:

用过C的人都知道每一个C的程序都会有一个main(),但有时看别人写的程序发现主函数不是int main(),而是int _tmain(),而且头文件也不是<iostream.h>而是<stdafx.h>,会困惑吧?一起来看看他们有什么关系吧首先,这个_tmain()是为了支持unicode所使用的main一个别名而已,既然是别名,应该有宏定义过的,在哪里定义的呢?就在那个让你困惑的<stdafx.h>里,有这么两行.
#include <stdio.h>#include <tchar.h>我们可以在头文件<tchar.h>里找到_tmain的宏定义     #define _tmain      main所以,经过预编译以后, _tmain就变成main了,这下明白了吧!
这通过后,可是问题又来了,编译成功后出现命令提示符后,一闪面过,不显示press any key to continue
再找百度,这样就可以了:
#include "stdafx.h"#include"stdlib.h"int _tmd(){std::cout<<"这是我的第一个C++程序\n";int x;std::cin>>x;std::cout<<x;system("pause");return 0;}
或者
#include "stdafx.h"#include"conio.h"int _tmain(){std::cout<<"这是我的第一个C++程序\n";int x;std::cin>>x;std::cout<<x;getch();return 0;}2种解决方案。
自己备份下,省得将来忘记了。
链接:http://blog.csdn.net/qq_25572699/article/details/43118999
 
阅读全文
0 0