在C ++代码中自动插入注释 [英] Automatically insert comments in C++ code

查看:163
本文介绍了在C ++代码中自动插入注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个工具,可以在C ++源代码中的特定位置插入注释。我正在一个类,其中教师是真正挑剔的在每个文件中有一个序言,每个功能的标题等。这个工具将允许我指定一些模板,所以我只需要回去填写

I'm looking for a tool that can insert comments at specific places in C++ source code. I'm taking a class where the instructor is real picky about having a prologue in each file, a "header" for each function, etc. This tool would allow me to specify some templates so I only have to go back and fill in the details.

这将是非常好的,如果我可以设置一些规则,例如:

It would be great if I could set up some rules, for example:

每个文件,在顶部添加以下块:

1) In each file, add the following block at the top:

// File Name: 
// Date:
// Author:
// Description:

2)在每个头文件中,在每个函数声明之前添加以下内容:

2) In each header file, add the following before every function declaration:

// Name:
// Arguments:
// Returns:

我在Visual Studio中工作,所以一个加载项集成到我的环境将是真棒,但即使一个独立的工具将比手动执行更好。

I'm working in Visual Studio, so an add-in that integrates right in to my environment would be awesome, but even a stand-alone tool would be better than doing this manually.

为了清楚,我不是在寻找像Doxygen这样的东西可以从我的源代码中的注释生成文档,而是一个可以通过添加注释记录我的源代码的工具。

Just to be clear, I'm not looking for something like Doxygen that can generate documentation from comments in my source code, rather a tool that can document my source code by adding comments.

我已经修改了Visual Studio的模板,我相信这将适用于示例#1,但这会影响我创建的每个文件,并且有点痛苦。

I have modified Visual Studio's templates before, and I'm sure that would work for example #1, but that would affect every file I create and is somewhat of a pain. The ideal solution would know a little bit more about the source code so I could more advanced rules.

推荐答案

没有做到这一点,但打算,我建议尝试制作一个代码片段并将其导入到VS.

Having not done it, but intended to, I would suggest attempting making a Code Snippet and importing it into VS.

您可以下载代码段编辑器, 。 MSDN提供了一个官方通过,如果你有兴趣。

You can download Snippet Editor for an easier approach. MSDN provides an "official" walk through if you're interested.

实际上,您可以创建一个接受您输入的注释,并在您完成任务的同时构建函数。一旦完成,您可以键入快捷方式,当它出现时,您可以按Tab键自动填充代码的整个部分,突出显示的提示,按照逻辑顺序,自动填充适当的原型等,如 class 代码段,你现在应该可以在VS中使用。

You could actually create one that accepts the comments you enter and builds the function simultaneously if you're up to the task. Once finished, you can type your shortcut when it comes up you can press tab to auto-fill the entire section of code with highlighted prompts that behave in a logical order and auto-fill appropriate prototypes etc. like the class snippet you should have available to you now in VS.

这篇关于在C ++代码中自动插入注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆