CLion 2017.3 Help

Creating Template-based Files

On this page:

Introduction

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 file name extension for a template-based file is set automatically so you don't need to specify it.

Creating a new file from a template

  1. Select the desired file type.
    • To create a new C++ class, select New | C++ class. In the dialog that opens:
      1. Specify the name of a class.
      2. From the drop-down 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.
      3. Select the Create header only checkbox if you want to create the header file only.
      4. Select the Add to targets checkbox to add the created files to the list of the source files for the selected target(s).
      5. Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created files.
        /help/img/idea/2017.3/cl_newClass.png
    • To create a new C/C++ source file, select New | C/C++ source file. In the dialog that opens:
      1. Specify the name of a file.
      2. From the drop-down 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.
      3. Select the Create an associated header checkbox if you want to create the respected header file as well.
      4. Select the Add to targets checkbox to add the created file to the list of the source files for the selected target(s).
      5. Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created file.
        /help/img/idea/2017.3/cl_newSourceFile.png
    • To create a new C/C++ header, select New | C/C++ header file. In the dialog that opens:
      1. Specify the name of a file.
      2. From the drop-down 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.
      3. Select the Add to targets checkbox to add the created file to the list of the source files for the selected target(s).
      4. Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created file.
        /help/img/idea/2017.3/cl_newHeaderFile.png
    In addition, the following file templates are also available:
    • HTML
    • Stylesheet
    • JavaScript
    • XSLT
  2. Click OK. The new file that corresponds to the selected file template will be created under the target location.
Last modified: 24 October 2017

See Also