CLion 2019.1 Help

Create Template-based Files

CLion provides file templates for most of the languages that it supports. This lets you create the files with the initial content appropriate for the file purpose.

Generally, the filename extension for a template-based file is set automatically so you don't need to specify it.

To create a new file from a template, do one of the following:

  • In the Project Tool Window, select the directory in which you want to create a new, and then choose File | New on the main menu.

  • Right-click the corresponding directory and select New from the context menu.

  • Press Alt+Insert.

  • Select the desired file type (the procedures for C++ class, C++ source, and C++ header files are given below).

Create a new C++ class

  1. Select New | C++ class.

  2. In the dialog that opens:

    • Specify the name of a class.

    • From the list, choose the type of the source and header files for the new class, if you want to change the default type which is defined in the New File Extensions tab of the Code Style C/C++ dialog.

    • Select the Create header only checkbox if you want to create the header file only.

    • Select the Add to targets checkbox to add the created files to the list of the source files for the selected target(s).

    • Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created files.

      New class

Create a new C/C++ source file

  1. Select New | C/C++ source file.

  2. In the dialog that opens:

    • Specify the name of a file.

    • From the list, select the source file type, if you want to change the default type which is defined in the New File Extensions tab of the Code Style C/C++ dialog.

    • Select the Create an associated header checkbox if you want to create the respected header file as well.

    • Select the Add to targets checkbox to add the created file to the list of the source files for the selected target(s).

    • Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created file.

      New Source file

Create a new C/C++ header

  1. Select New | C/C++ header file.

  2. In the dialog that opens:

    • Specify the name of a file.

    • From the list, select the header file type, if you want to change the default type which is defined in the New File Extensions tab of the Code Style C/C++ dialog.

    • Select the Add to targets checkbox to add the created file to the list of the source files for the selected target(s).

    • Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created file.

      New header file

Last modified: 24 July 2019

See Also