"C + +" uses Visual Studio 2008 to write basic usage of C++,visual Studio 2008

Source: Internet
Author: User

Now many colleges and universities still use the classic version of Visual C + + 6.0 to teach C + +, many people's memories of their first program is the use of Visual C + + 6.0 in C language HelloWorld, and then learn the C + + class, but still using Visual C + + 6.0. As a result, Visual Studio has changed the Visual C + + 6.0 interface to a larger extent, and most people will be using Visual C + + 6.0 if they want to write C + +, or even find a way to run Visual C + + 6.0 under Win8. And then get a virtual machine or something like that. has been a new type of C language writing tools, not afraid to use. In fact, Visual Studio 2008 is more convenient than Visual C + + 6.0 after it has been cooked.

Visual Studio 2008 downloads are not available here, as this thing is like office, a bunch of online search, and then a variety of free easy to use version flying. The only thing to note is that we're just playing on our own, so it's good to use the Professional version of Visual Studio 2008. After that, the installation of Visual Studio 2008, like everything else in Microsoft, was very slow to install even after extracting the ISO version of the WinRAR. Please wait patiently.

When you install Visual Studio 2008, you also need to close other programs, choose a full installation, and restart.

I. Basic use of Visual Studio 2008

1. After installation, open Visual Studio 2008, like VC6, must have the project first, in order to have CPP. For example, new project, file- Create a new project, where the project is called an item. is actually a folder.

2. After that, select the Win32->win32 console application in Visual C + +. and choose the location of the project. Also enter the name of the project, here is HelloWorld. It is important to note that Visual Studio 2008 is next to the location you choose, and then create a new folder based on the name of the project. Therefore, there is no need to create a separate folder for this project when selecting the project location.

The solution is the same as the project name. This is equivalent to the engineering space in Visual C + +, and you can open the project based on this. I don't know what's the use for the moment anyway.

If you do not see Visual C + +, it is likely that the default programming language chose something else when you installed it. It's just hiding in "other languages." I downloaded this version, "Other languages" included in C # and VB, Visual Studio 2008 is very powerful, can also be used to write projects in other languages. It is also equivalent to the Fortress Eclipse, and can also get some other language plug-ins, write more languages.

3, get HelloWorld this project, directly right-click the source files, such as, a new item, is actually a file.

4, for example, select C + + files. Names can be identical to folders.

5, after, you can write code, the process of writing code, Visual Studio 2008 will help you automatically indent. At the end of the day, you can also select all the code to automatically typeset the code through CTRL+K,CTRL+F. Equivalent to the Alt+f8 function of VC6. By Ctrl+j can summon code hints, equivalent to VC6 's ctrl+space, with Eclipse's alt+/(?)

However, some versions of visual Studio 2008 may not have code hints turned on by default.

You can check automatically list members by using the general, all languages, text Editor, tools, options, and so on.

You can also bring up the line number here.

Ii. use of the Visual Studio 2008 Debugger and program operation

by double-clicking any line of code, the blank next to the line number, you can set the endpoint and start debugging with F5.

Note here to distinguish between debugging and normal operation, press F5 equivalent to press the Toolbar Play button, start debugging, into the debugging interface. Press Ctrl+f5 is to start the program directly, will not enter the debugging interface, written out of the program basically even if you do not write system ("pause"), or GetChar ();

In the process of debugging, F11 can jump to a sentence, shirf+f11 can jump to a breakpoint.

Please also note the output of the console.

The debug result of adding a breakpoint to the output language of the two sentences.

If part of Visual Studio 2008 is debugging to the last occurrence of a flash, you can add: System ("pause") at the end, or GetChar ();

GetChar (); Here does not parse, like VC6, let the user enter the end of the word characters program. System ("pause"); Is it a new item, or am I mars?

Here casually say, remember to write using namespace Std; otherwise it will appear:

"Error C2065:" cout ": undeclared identifier" with "Error C2065:" Endl ":" Undeclared identifier ",

None of the sentences here can be saved.

At the same time, the standard C + + rule that the main function must be declared as int, the program returns 0 normally, otherwise-1. We are still the standard point, to close the void main bar ...

In program development, it is often necessary to use a toolkit developed by others, such as OpenCV and ITK. In general, in vs2008, the source files are seldom used, most of which are the header files that are declared on the class and the link libraries (static lib or dynamic DLLs) that encapsulate the class.

If you want to use these classes, you need to include the name of the header file in the file, such as # include "Cv.h". But this is not enough, because this file is generally not in the current directory, there are two ways to solve this problem. One, the inclusion of the header file copied to the current directory (another article has written), this comparison has limitations, because if the header file too much, this is more troublesome. Second, include the path where the header file is located, that is, add the include (include) file directory. Two methods: A. Open the "project--Properties--Configuration Properties--c++--General-Additional Include directories" to add all the paths. It is important to note that (1) the path must point to the subfolder where the header file is located, not until the parent folder ends (2) Each path does not need double quotation marks, after input, VS2008 will automatically add double quotes, if you add possible vs2008 cannot recognize double quotation marks (3) if it is more than one path, The path is separated directly by ";". b.[Menu] Tools, Options, projects and Solutions->c++ directory, select the appropriate platform, and then add the required include files directory.

In addition to the header file, you need to tell the compiler where the class is implemented, that is, where the library of the encapsulated class is, so that the program can execute functions in the toolkit.

You first need to enter the path of the link library into vs2008, which is the Add library (libs) file directory. Two methods: A. Open the path to the link library in project-Properties-Configuration Properties-linker-General-Additional library directory. b.[Menu] Tools, Options, projects and Solutions->c++ directory, select the appropriate platform.

Then add the desired library file directory, which is the Lib file to add the required (dependent) compilation. Add the name of the link library to the project-Properties-Configuration Properties-linker-general-input-additional dependencies, and multiple lib are separated by spaces. (equivalent to "#pragma comment (lib," Xxx.lib ")" statement).

C + + uses Visual Studio 2008 to write basic use of C++,visual Studio 2008

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.