Create template-based files
Last modified: 11 January 2023CLion 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.

tip
To edit file templates, call Edit File templates from the Project view context menu or go to Settings | Editor | File and Code Templates.
Create a new C++ class
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.
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.
Use the Namespace field when you need to specify the namespace for the new class.
If you specify a nonexistent namespace, it will be created along with the new class. To specify an unnamed namespace, type a blank space.
tip
The 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.
Select the Add to targets checkbox to add the created files to the list of the source files for the selected target(s).
tip
See Adding files to CMake projects for details.
Select the desired CMake target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created files.
Create a new C/C++ source file
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.
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).
tip
See Adding files to CMake projects for details.
Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created file.
Create a new C/C++ header
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.
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).
tip
See Adding files to CMake projects for details.
Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests to add the created file.
Thanks for your feedback!