在Visual Studio中插入包含保护的快速方法
Fast way to insert include guard in Visual Studio
我想在Visual Studio 2012中新创建的头文件中自动插入include守卫。是否有用于此目的的预定义代码片段?
编辑:我知道#pragma曾经和它的广泛支持编译器。但是我们的编码风格迫使我使用include保护符
在visual studio 2012中使用组合键
Ctrl+K,Ctrl+S
它允许你用代码片段包围选定的代码,例如:
#if
, #ifdef
, #ifndef
, if
, class
, do
, enum
,以及更多
. .或者指定你自己的:http://msdn.microsoft.com/en-us/library/ms165394.aspx
#pragma once
?
但是不,我不知道有什么可以自动为您插入#ifndef
等
由于您正在标记c++,您应该通过内置向导添加类。向导创建#pragma once指令。这甚至对其他编译器也是可用的:#pragma一次,这样你就不会破坏平台的交叉兼容性。
然而,你可以做的是创建一个像这样的VS宏:Option Strict Off
Option Explicit Off
Imports System
Public Module HeaderGuard
Sub InsertHeaderGuard()
Dim filename As String = DTE.ActiveDocument.Name
filename = filename.ToUpper().Replace("."c, "_"c)
DTE.ActiveDocument.Selection.Text = "#ifndef " + filename
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "#define " + filename
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "#endif /* " + filename + " */"
DTE.ActiveDocument.Selection.NewLine()
End Sub
End Module
如果您有Visual Assist X,您可以删除#pragma once
(如果存在),选择其余文本,右键单击Surround with (VA)
=> #ifdef guard in a header
。如果你不喜欢默认设置,你可以在VASSISTX
菜单中选择Tools
=> Edit VA Snippets...
你可以使用像autohotkey这样的工具。下面是一个类似问题的答案。
相关文章:
- 覆盖作为另一个类的好友的虚拟受保护方法
- 无法在赋值运算符中访问基类的受保护方法
- 如何按类型启用受保护的方法
- 用受保护的继承指向基类方法
- 受保护的方法在 c++ 中继承时可以成为私有方法
- std::异步不能调用受保护的基类方法
- Boost单元测试夹具继承测试类,是否可以访问受保护的方法
- 在派生类中定义自定义返回类型的受保护方法
- 有什么方法可以在工会内部获得受保护的声明吗
- 通过此指针调用受保护的基类方法,该指针投射到派生类(C++)中的基类
- 访问受保护成员的公共方法
- 在C++类中构建互斥保护的线程安全方法
- C++:重写由另一个方法调用的受保护方法
- 这种使用虚拟受保护方法扩展库的方式是否安全
- 派生类是否可以访问作为内部类的好友的父类的受保护内部类的私有方法
- 为什么无法从模板方法访问此类自己的受保护成员?
- 从基类的静态模板方法中调用继承类的受保护 ctor 失败
- 在C++中为成员对象调用受保护的方法
- 通过 DllImport 在 C# 中调用 C 方法 - 尝试读取或写入受保护的内存
- 多线程:我需要用只读方法保护我的变量吗