Visual C++ 2008 无法启动程序,系统找不到指定的文件

来源:互联网 发布:自定义 仅安装windows 编辑:程序博客网 时间:2024/05/29 12:42

用Visual C++ 2008 新建C++项目后,运行时报错,
代码如下:只是简单的打印helloworld
HelloWorld.cpp

#include <iostream>using namespace std;int main(){    cout << "Hello, world!" << endl;    return 0;}

报错信息如下

1>------ 已启动生成: 项目: HelloWorld, 配置: Debug Win32 ------1>正在编译...1>helloworld.cpp1>正在编译资源清单...1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.11>Copyright (C) Microsoft Corporation.  All rights reserved.1>正在链接...1>MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用1>e:\Users\Visual Studio 2008\Projects\HelloWorld\Debug\HelloWorld.exe : fatal error LNK1120: 1 个无法解析的外部命令1>生成日志保存在“file://e:\Users\Visual Studio 2008\Projects\HelloWorld\HelloWorld\Debug\BuildLog.htm”1>HelloWorld - 2 个错误,0 个警告========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

截图信息
这里写图片描述

原因:新建项目类型时应该选择 控制台应用程序(对应的函数入口为main()方法),但是却错误的选择了Windows应用程序(对应的函数入口不是main()方法,而代码中却写的是main()方法),从而导致不能正常执行main()方法,报错找不到执行程序

这里写图片描述

这里写图片描述

二、调试成功后控制台一闪而过解决方案:
在代码中加入

system("pause");//或者 //char c;//c=getchar();

完整代码:

#include <iostream>using namespace std;int main(){    cout << "Hello, world!" << endl;    system("pause");    return 0;}

参考:
http://blog.csdn.net/playstudy/article/details/6661868
http://blog.csdn.net/zhangzhengyuan123123/article/details/38876321
https://www.cnblogs.com/iczelion/p/6064120.html

阅读全文
0 0
原创粉丝点击