为什么我的VC++总出错

来源:百度知道 编辑:UC知道 时间:2024/06/14 15:51:44
我的程序是:
#include "iostream.h"
struct Point
{
int x;
int y;
};
void main()
{
Point pt;
pt.x=5;
pt.y=5;
cout<<pt.x<<endl<<pt.y<<endl;
}

结果:--------------------Configuration: point - Win32 Debug--------------------
Compiling...
point.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/point.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

point.exe - 1 error(s), 0 warning(s)

你建立一个console程序,然后复制这段代码放到文件里。

或者修改入口函数
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
);

#include "iostream.h"
struct Point
{
int x;
int y;
};
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
Point pt;
pt.x=5;
pt.y=5;
cout<<pt.x<<endl<<pt.y<<endl;
return 0;
}

如果你是在建立app wizard(.exe)这个工程那么原因就是你的Point对象与系统的Point类重名了。
如果不是,我在C++源文件中式了一下,没问题

新建工程的时候如果是选的win32 application,就应以winmain作入口。
建议新建win32 console application,把这个cpp文件加到工程里;
或者单独把这个cpp文件放在某个空文件夹,直接编译,生成工程文件