Visual Studio

One of the most popular IDEs is Visual Studio. Visual Studio is a catch-all term, so be careful when you use it for different things. VS includes a compiler for C++ (and other languages such as C#), a source code editor, linker, debugger, and can do extras like basic testing, refactoring, and visual outlining your code. Remember: You can get a full version of Visual Studio from Imagine Links to an external site. as a UCF student.

vs.png
(This is a shot of a simple C++ SAXPY program in "debug" mode in Visual Studio 2015.)

Visual Studio's code editor supports syntax highlighting and code completion. (In my opinion) Visual Studio's compiler is the weakest part. They commonly lag behind implementing newer C++ features, and favor their own odd ball features like .NET, CLR, MFC and other Microsoft-specific features that get you in trouble when you try to port code to Linux or MacOS.

The best feature (and why you keep coming back) is the super powerful debugger. The debugger is widely regarded as the easiest and most intuitive to use. (There is a detailed section on debugging as another module later in the foundation course.)

(Semi-hidden) Features

Here are some fun features that are semi-hidden, not initially intuitive, when you are starting out. Visual Studio is a bloated interface with many right-click and hidden menus.

Building a ProgramOne of the first things you want to do is to build your program. Here build specifically refers to compiling and linking your program. (When we talk about errors and debugging it is important to understand the fundamental difference of these operations.) But I will commonly just build (F7) the code to see that it compiles.

build.png

Running a program: One of the first things you want to do is run and test your program. The feature is found under Debug->Start Debugging or Debug->Start without Debugging. You will quickly realize the shortcuts F5 and Ctrl-F5.  - Note: VS gives a prompt if your program errors, the first time you install it .. do you want to run the last working version. Check never show me again, and No. Never do I want to do that.

run.png

Configuration and Platform: Often you want to test different configurations : Debug and Release. We will go over differences in detail later. But simply Debug adds bloat to step through and debug the program so it runs much slower. Release is what you want to deploy but you cannot debug.

Common pitfalls are not being able to debug a release version .. and not realizing why, or performance timing a debug mode program. Huge mistakes. You want to debug a debug configured program, and performance time a release configured program.

The other thing to note is Platform Architecture: 32bit or 64bit (x64). You need everything compile to the same configuration or you get odd errors. But in this day, just keep everything x64 unless you specifically need to go down.
x64.png

 

Code Completion: In the example below I am attempting to type "runtimes" which is the variable a few lines above. Ctrl-Space will call up a menu (sometimes happens automatically depending on settings) that will start to list the possibilities and help complete it so you don't make any mistakes for longer names.

comp.png

Browsing Definitions: Say I have a class Timer and a method start(). Say you were curious what those methods were .. either because you forgot the exact syntax, algorithm, or just did not write it. You have two very helpful options. Peeking or Go To a definition.

options.png

 The first is "peeking" a definition. This feature (shown below) places the method directly under where you called it which is helpful just to peek at what is happening, or a quick reference.

peek.png

The next method is Go To Definition which opens the whole file in the code editor and highlights the method, but let's you see everything in context. This great for longer methods, or just getting a feel for what is happening.

goto.png

 
Whitespace, Block comments, and Line Numbers: There is a massive debate about space vs. tabs. (Spaces. Spaces. Spaces. Spaces. Spaces. Why would you ever want to use tabs? - see what I did there?) Anyhows people like the brevity of tabs, and people like how spaces are constant across ides architectures, etc and tabs are not. I think you need to turn line numbers on and white spaces on immediately in your IDE. (again a bit of a preference, some people find it distracting.) But if someone walks up and points something out, using line numbers to navigate works much better.

whitespace.png
Here notice the red highlights for line numbers and tabs. (really who uses tabs.)

To display line numbers in code. On the menu bar, choose Tools, Options. Expand the Text Editor node, and then select either the node for the language you are using, or All Languages to turn on line numbers in all languages. Or you can type line number in the Quick Launch box.

line.png

For whitespace viewing: CTRL-R, CTRL-W : Toggle showing whitespace or Edit -> Advanced -> View White Space

Under the Edit->advanced menu There are some great feature like converting tabs to spaces (tabify or untabify) , block commenting or uncommenting code (very useful shortcuts to memorize), indenting, etc

tabify.png

Project dependencies: Say you built a library or using library and you need to ensure it is built before the code the depends on it (Otherwise you get a slew of errors). ... and you did not use a Build System and specify this or whatever the reason. Project->Project Dependenciesdepen.png

Project Properties: one of the most helpful and hidden menus (and sometimes hardest to initially wrap your head around. Is the Project Properties menu.

properties.png

I will quickly split up this menu into 3 parts : general, C++ (for compiling), and Linker (for linking).

(1) General: General lets you set features like Target extension (exe, DLL, or maybe MLL if you need something custom), Character-set, CLR (if you like the dark arts), toolset, etc.

2017-01-09 20_51_13-inverse Property Pages.png

(2) C++ (Compiling): All things you need for compiling can be found under this menu. The main thing to check are the "Additional Include Directories" to make sure you the code compiling can see everything it needs to. But optimization and Run Time Library (Code Generation) are also important to know where those features are located. When you have a non-syntax related compiling issue, look here.

c++.png

(3) Linker (for linking): This set of features is for everything linking related. Telling the program where the lib files are that you are including, and things like that. Input->Additional Dependencies, and General->Additional Library Directories are the two most used features here. When you have a linking issue, look here.

link.png