You can use the File Template extension.
C++ files are not included in its default list of supported file types. But it does support adding your own templates for known VS Code language identifiers, such as .cpp
for C++ files.
To set it up, follow the instructions on the extension's page:
- Install the extension
- Go to the extension's templates directory
gino@templates$ pwd
/Users/gino/.vscode/extensions/ralfzhang.filetemplate-2.0.4/asset/templates
- Create a file named cpp.tmpl
- Write your template code
gino@templates$ vim cpp.tmpl
gino@templates$ cat cpp.tmpl
#include <iostream>
using namespace std;
int main(){
}
To use it:
- Restart VS Code (might not be needed, but just to be sure)
- Create a file with a
.cpp
extension
- Open the command list (CMD+Shift+P on Mac or Ctrl+Shift+P on Linux/Windows)
- Run the command "Tmpl: Create Template"

The .cpp
file will be populated by the contents of cpp.tmpl
.

If you want to be fancy with your template, according to the extension's documentation, the template follows the TextMate syntax. In my example above, I just used plain C++ code and it worked OK.