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">
        <Header>
            <Title>for</Title>
            <Shortcut>for</Shortcut>
            <Description>Code snippet for 'for' loop</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>index</ID>
                    <Default>i</Default>
                    <ToolTip>Index</ToolTip>
                </Literal>
                <Literal>
                    <ID>max</ID>
                    <Default>length</Default>
                    <ToolTip>Max length</ToolTip>
                </Literal>
            </Declarations>
            <Code Language="cpp"><![CDATA[for (int $index$ = 0; $index$ < $max$; ++$index$) {
            $selected$ $end$
      }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

No comments: