【问题标题】:How to make CLion use "#pragma once" instead of "ifndef ... def ..." by default for new header files?如何让 CLion 默认使用“#pragma once”而不是“ifndef ... def ...”来处理新的头文件?
【发布时间】:2015-10-12 18:34:56
【问题描述】:

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

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

但我更喜欢#pragma once。如何配置 CLion 使其默认使用 #pragma once 来处理新的头文件?

【问题讨论】:

标签: include header-files clion pragma include-guards


【解决方案1】:

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

【讨论】:

  • 我应该如何修改它以便它使用#pragma once
  • 注意:#pragma 是无效的Apache Velocity 模板,因为#foo 将被解析为名为@9​​87654333@ 的指令。在这里使用literal syntax 更安全,比如#[[#pragma]]# once
  • escape the directive,如\#pragma once
  • 对于CLion 2021, use CLion > Preferences... > Editor > File and Code Templates > C++ Class Header
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
  • 2015-06-07
  • 2010-12-27
  • 2015-05-13
相关资源
最近更新 更多