CLion 2024.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.

There are four templates for C/C++: C++ Class, C++ Source File, C++ Header File, and C++ Module Interface Unit.

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. New C++ class dialog
    • Specify the name of the new class.

    • Use the default file type or choose from the drop-down list:

      New class file extensions

      Click the spanner icon to access the default file extensions settings:

      File extensions settings
    • In the Namespace field, set the namespace for your class.

      If you specify a nonexistent namespace, it will be created along with the new class.

      This field has basic validation checking for whether the identifier is a valid namespace name (or a blank space).

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

    • CLion can automatically add files to CMake targets.

      Select the target from the list or click Add new target to create a new one. For more information, refer to Adding files to CMake projects.

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. Adding a new source file
    • Specify the name of the new file.

    • Use the default file type or choose from the drop-down list:

      New C++ file extensions

      Click the spanner icon to access the default file extensions settings:

      File extensions settings
    • Select the Create an associated header checkbox to create the corresponding header file as well.

    • CLion can automatically add files to CMake targets.

      Select the target from the list or click Add new target to create a new one. For more information, refer to Adding files to CMake projects.

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. Adding a new header file
    • Specify the name of the new file.

    • Use the default file type or choose from the drop-down list:

      New C++ header extensions

      Click the spanner icon to access the default file extensions settings:

      File extensions settings
    • CLion can automatically add files to CMake targets.

      Select the target from the list or click Add new target to create a new one. For more information, refer to Adding files to CMake projects.

Last modified: 16 April 2024