本文共 3237 字,大约阅读时间需要 10 分钟。
效果演示:
详细步骤如下:(下面使用VS 2019界面演示)
1.【工具】——》【代码片段管理器】
这里只简单的说明一下如何编写一个snippet文件,我们可以参考 Visudal C++ 提供的Snippets 编写自己的snippet文件。
以下博主编写的Show()函数代码,仅供参考:
show sh show 循环的代码片段 Microsoft Corporation Expansion SurroundsWith vec # 标签void # 默认值自动类型迭代容器元素 # 说明void Show(const _Ty& Container) { for (const auto& it : Container) { std::cout << it << " "; } std::cout << std::endl; } ]]>
经测试,代码部分的内容会在编译器中输出关键字后按照原样展开。而如果有变量,可以使用 $name$
的方式添加到代码中。
方法一:将文件直接拖到工作目录(如图所示)
在【代码片段管理器中】选择【Visudal C++】,记住目录位置
函数(注释模板引用自:https://blog.csdn.net/ghevinn/article/details/44831841)
comment_func cf # 唤醒词 cf函数注释 Microsoft Corporation Expansion SurroundsWith func functions 函数名
效果展示:
file_comment cf # 唤醒词 cf文件注释 Microsoft Corporation Expansion SurroundsWith fileName # 标签fileName # 默认值文件名称 # 说明
效果展示:
CShow csh # 唤醒词 csh使用std::copy 打印 Microsoft Corporation Expansion SurroundsWith void CShow(const _Ty& cont) { std::copy(cont.cbegin(), cont.cend(), std::ostream_iterator<_emT>(std::cout, " ")); std::cout << std::endl; } ]]>
效果展示:
在代码片段管理器中可以看到在目录F:\....
下的所有snippet文件,其中函数的说明,快捷方式等都标注在右侧。