如何让 CLion 默认使用“#pragma once”而不是 "ifndef ... def ..." 作为新的头文件?

How to make CLion use "#pragma once" instead of "ifndef ... def ..." by default for new header files?

默认情况下,CLion 会将以下行添加到新创建的头文件中:

#ifndef SOME_NAME_H
#define SOME_NAME_H
.... your code here
#endif //SOME_NAME_H

但我更喜欢#pragma once。如何配置 CLion,使其默认使用 #pragma once 作为新头文件?

前往 File-> Settings -> Editor -> File and Code Templates。您会发现有 3 个选项卡,即 TemplatesIncludesCode。现在在 Templates 下选择 C Header 文件。插入 #pragma once 以替换其内容。现在,每次从项目菜单中添加新的 Header 时,您都会拥有自己的模板。