[C ++] use Visual Studio 2008 to write C ++, Visual Studio 2008 using basic

Now many universities still use Visual C ++ 6.0 this version of the classic teaching C ++, many memories of his first program is the use of Visual C ++ 6.0 with the C language to write Helloworld, after re-learning C ++ classes, but still in use Visual C ++ 6.0. Then arrange for Visual Studio Visual C ++ 6.0 interface changes than larger, if a majority of people want to write C / C ++ or Visual C ++ 6.0 will be used, even struggling to find ways to run Visual C ++ under win8 6.0, followed then get hold virtual machines and the like. Authoring tools have been a closely guarded secret of the new C language, not to use. In fact, Visual Studio 2008 after using this stuff cooked, Visual C ++ convenient than the more than 6.0.

Visual Studio 2008 to download here is not provided, since this thing with the Office as a search online in a pile and a variety of easy to use free version everywhere. The only note is that because of our own personal just playing, so using Visual Studio 2008 Professional Edition is just fine. After, Visual Studio 2008 installed with Microsoft's other stuff like that, even after the use of high iso version winrar unpack, install very very slow. please wait patiently.

Install Visual Studio 2008 when it need to close other programs, select a full install, and restart.

A, Visual Studio 2008 using basic

1. Once installed, open Visual Studio 2008, and VC6 Like, you have to have the project in order to have cpp. The following diagram, File -> New -> Project. Create a new project, where the project called into the project. It is actually a folder.

2, after selecting Win32-> Win32 console application in Visual C ++. And choose the right location for this project. Enter the name of the project at the same time, there is Helloworld. It is noteworthy that, Visual Studio 2008 is the next in a location of your choice, and then under the project name and then create a new folder. So there is no need, select the item position in time for the project to build a separate folder.

Solution to the same project name. This project cargo space is equivalent to the Visual C ++, you can open the project in accordance with this. Anyway, not yet know what purpose.

If you see Visual C ++, you probably installed when the default choice of the programming language of the other. It is simply hidden in the "other language" in. I downloaded this version, inside the "other languages" also includes C # and VB, Visual Studio 2008 can be seen very powerful, can also be used to write other languages ​​of the project. It is also equivalent to the bunker Eclipse, plug-ins can also get some other languages, write more languages.

3. After obtaining Helloworld this project, just right's source file, as shown below, a new item is actually a file.

4, as shown below, to select C ++ files. The name of the folder can follow exactly the same.

5, after which you can write the code, and in the process of writing code, Visual Studio 2008 will help you automatically indent. Wrote Finally, you can put all the code select all, by Ctrl + K, Ctrl + F typesetting code automatically. The equivalent of alt + F8 function VC6. By Ctrl + J can call up code hints, the equivalent of Ctrl VC6 + Space, and the Eclipse Alt + / (?)

But some versions of Visual Studio 2008 may not enabled by default code hints.

By tool - "Auto List Members"> General, tick -> Options -> Text Editor -> all languages.

At the same time where you can adjust the line number.

Two, Visual Studio 2008 running with the program using the debugger

Double-click any blank space next to the line of code line number, you can set the endpoint, it can pass F5 to start debugging.

这里注意区分调试与正常运行,按F5的话等同按工具栏的播放按钮,开始调试,进入调试界面。按Ctrl+F5是直接开始程序的运行,不会进入调试界面,写出来的程序基本上即使不写system("pause");或者getchar();也不会一闪而过。

在调试的过程中,F11能跳到一下句,Shirf+F11能够跳到一个断点。

请同时注意控制台的输出。

在两句输出语言中加断点的调试结果。

如果部分Visual Studio 2008在调试到最后出现一闪而过的情况,可以在末尾加上:system("pause");或者getchar();

getchar();这里不解析了,像VC6一样,让用户输入完字符才结束程序。system("pause");则是新货,还是我火星了?

这里随便说一句,记得写using namespace std;否则会出现:

“error C2065: “cout”: 未声明的标识符”与“error C2065: “endl”: 未声明的标识符”的错误,

这里任何一句都不能省。

同时,标准的C++规定main函数必须声明为int型,程序正常结束返回0,否则-1。我们还是标准点,收起void main吧……

 

在程序开发中,很多时候需要用到别人开发的工具包,如OpenCV和itk。一般而言,在vs2008中,很少使用源文件,大部分是使用对类进行声明的头文件和封装了类的链接库(静态lib或动态dll)。

     如果要使用这些类,需要在文件中包含头文件的名字,如#include “cv.h”。但这个并不够,因为这个文件一般来说不在当前目录下,有两种方法解决这个问题。一,将所包含的头文件复制到当前目录(另一篇文章有写)下,这个比较有局限性,因为如果头文件太多,这样比较麻烦。二,将头文件所在的路径包括进去,即添加包含(include)文件目录。两种方法:A.依次打开“项目——属性——配置属性——C++——常规——附加包含目录”中加入所有的路径。这里需要注意的是(1)路径必须指向头文件所在的子文件夹,而不能直到父文件夹就结束(2)每个路径不需要加上双引号,输入了之后,vs2008会自动加上双引号,如果自己加可能vs2008无法识别双引号(3)如果是多个路径,路径直接用“;”隔开。B.[菜单]“工具->选项->项目和解决方案->C++ 目录”,选择对应平台,然后添加所需“包括文件”目录。

      除了头文件以外,也需要告诉编译器,类在哪里实现的,即封装类的链接库在哪里,这样程序才能执行工具包中的函数。

      首先需要将链接库的路径输入vs2008,即添加库(libs)文件目录。两种方法:A.依次打开“项目——属性——配置属性——链接器——常规——附加库目录”中加入链接库的路径。B.[菜单]“工具->选项->项目和解决方案->C++ 目录”,选择对应平台。

      然后添加所需“库文件”目录,即添加编译所需要(依赖)的 lib 文件 。在“项目——属性——配置属性——链接器——常规——输入——附加依赖项”中加入链接库的名字,多个lib用空格隔开。(等同于“#pragma comment(lib, “xxx.lib”) ”语句)。

Guess you like

Origin blog.csdn.net/Qsir/article/details/89333988