CLion 2020.1 Help

Create Template-based Files

CLion provides file templates for most of the supported languages. These templates help you create files with initial content already present. For example, there are three templates for C/C++: C++ Class, C++ Source File, C++ Header File.

File templates for C/C++

Create a new C++ class

  1. In the Project tool window, select the directory in which you want to add new files. Right-click it and select New | C++ Class from the context menu.

  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. In the Project tool window, select the directory in which you want to add new files. Right-click it and select New | C/C++ Source File from the context menu.

  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. In the Project tool window, select the directory in which you want to add new files. Right-click it and select New | C/C++ Header File from the context menu.

  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: 3 June 2020