Home > database >  How to autofill code with initials or shortcut line of code in Visual Studio 2019?
How to autofill code with initials or shortcut line of code in Visual Studio 2019?

Time:12-01

For example i want to write (rand%(MaxValue-MinValue 1))-MinValue i don't want to write this line everytime i want to use it but is there a way to make Visual Studio auto write it when i just need to write rand or R.

CodePudding user response:

why not use #define? example:

#define rand(r,max,min) ((r%(max-min 1))-min)

// use:

rand(_rand, MaxValue, MinValue);

CodePudding user response:

I recommend you to use snippet, it's very convenient.

You need to create a new txt file on the desktop, and then enter the following code in the file.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>propertyName</Title>
      <Shortcut>rand</Shortcut>
    </Header>
    <Snippet>
  <Code Language="cpp">
    <![CDATA[
    (rand%(MaxValue-MinValue 1))-MinValue
    ]]>
  </Code>
  <Declarations>   
  </Declarations>
</Snippet>
  </CodeSnippet>
</CodeSnippets>

Then change the suffix of the txt file to snippet, and finally import the snippet according to the method in the enter image description here

enter image description here

  • Related