2.2 C++(www.cppentry.com)的特性(2)
在Win32 Console Application-Step 1 of 1中,选择An empty project单选按钮,单击【Finish】按钮,如图2.6所示。
出现一个工程信息窗口,单击【OK】按钮,如图2.7所示,这样就生成了一个空的应用程序外壳。
|
| 图2.6 选择An empty project选项 |
|
| 图2.7 新工程信息 |
这样的应用程序外壳并不能做什么,甚至不能运行,我们还要为它加上源文件。单击【File】菜单,选择【New】;然后在Files选项卡下,选择C++(www.cppentry.com) Source File,如图2.8所示。
|
| 图2.8 为程序增加C++(www.cppentry.com)源文件 |
在右边的File文本框中,输入文件名EX03,单击【OK】按钮,如图2.9所示。
|
| 图2.9 输入C++(www.cppentry.com)源文件名称 |
并在EX03.cpp文件中输入以下代码:
例2-5
- #include <iostream.h>
- class point
- {
- public:
- int x;
- int y;
- void output()
- {
- cout<<x<<endl<<y<<endl;
- }
- };
- void main()
- {
- point pt;
- pt.output();
- }
说明:在这一章中,我们所有的示例工程都通过上述方式创建。
提示:如果你在编译程序时出现了下面的错误,请想想错误的原因,然后参照1.5节给出的问题解决办法,解决下面的错误。
- --------------------Configuration: EX03 - Win32 Debug--------------------
- Compiling...
- EX03.CPP
- Linking...
- LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
- Debug/EX03.exe : fatal error LNK1120: 1 unresolved externals
- Error executing link.exe.
-
- EX03.exe - 2 error(s), 0 warning(s)