Tuesday, October 11, 2011

Sample CodeSnippet for C++ in VisualStudio

To enable code snippets in VisualStudio 2005, you need to install Microsoft Visual Studio 2005 IDE Enhancements

You can write your code snippets however you want, see the below example for 'for' code snippet:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
            <Description>Code snippet for 'for' loop</Description>
            <Author>Microsoft Corporation</Author>
                    <ToolTip>Max length</ToolTip>
            <Code Language="cpp"><![CDATA[for (int $index$ = 0; $index$ < $max$; ++$index$) {
            $selected$ $end$

Microsoft Visual Studio 2005 IDE Enhancements

Visual Studio 2005 IDE Enhancements are a set of Visual Studio extensions that are designed to make you more productive. These enhancements are directly integrated into the Visual Studio IDE. This set of enhancements includes Source Code Outliner, Visual C++ Code Snippets, Indexed Find, Super Diff and Event Toaster tools. All these tools except the IDE Event Toaster can be invoked from Visual Studio’s View.OtherWindows menu group. The Event Toaster tool can be configured from the Tools Options dialog under the PowerToys node. The Visual C++ Code Snippets can be invoked on any C++ source file. Previously, these enhancements were only available via the Visual Studio 2005 SDK. This installation does not require Visual Studio 2005 SDK.
Source Code Outliner : The Source Outliner tool is a Visual Studio extension that provides a tree view of your source code's types and members and lets you quickly navigate to them inside the editor.
Visual C++ Code Snippets:The Visual C++ Code Snippets tool lets you insert snippets in your code by using a pop-up menu that contains programming keywords. VB.NET and C# languages have this functionality in Visual Studio 2005.
Indexed Find : The Indexed Find tool is a Visual Studio extension that uses the Microsoft Indexing Service to provide improved Search capabilities to the integrated development environment (IDE). It sends the results of a search to the Output Window.
Super Diff Utility: The Super Diff Find tool is a Visual Studio extension that compares text files. It uses color coding and graphics to show the difference between the files in deleted text (red), changed text (blue), inserted text (green).
Event Toaster Utility: The Event Toaster tool is a Visual Studio extension that notifies users about specific events within the Visual Studio IDE.

Visual Studio Color Scheme

You can find so many color schemes here.

Cyclomatic Complexity

Checkout here:

  1. add 1 for each if statement
  2. add 1 for each for statement
  3. add 1 for each while loop
  4. add 1 for each do-while loop
  5. add 1 for each && (an implied if statement)
  6. add 1 for each || (an implied if statement)
  7. add 1 for each ? (an implied if statement)
  8. add 1 for each . (an implied if statement)
  9. add 1 for each case statement
  10. add 1 for each default statement
  11. add 1 for each catch statement
  12. add 1 for each finaly statement
  13. add 1 for each continue statement