2

Is there any way to make VSCode add this code below to every new file i create? or only the ones with .cpp extension

#include <iostream>
#include <iomanip>
#include <math.h>
 
using namespace std;
 
int main() {
 
    return 0;
}

this would make life easier as i wouldn't need to CTRL+C and V every time i create a new file

Levy Barbosa
  • 342
  • 1
  • 5
  • 13
  • Related: https://stackoverflow.com/questions/56608835/how-can-i-set-up-a-default-code-for-c-in-visual-studio-code – Shub Aug 04 '23 at 05:45

1 Answers1

1

I'm afraid it isn't possible without an extension, although you can write an snippet to make your work easy.

To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language. Write the following in the file and save it:

{
"Default file": {
    "prefix": "main",
    "body": ["#include <iostream>", "#include <iomanip>", "#include <math.h>", "\nusing namespace std;", "\nint main() {", "\nreturn 0;", "\n}"],
    "description": "My default cpp file"
}

}

Now, in some *.cpp file, start write "main" and VSCODE will show you the complete word. Just hit tab and voila.

awquadros
  • 519
  • 3
  • 4