如何使用#pragma message()以便消息指向文件(lineno)? [英] How can I use #pragma message() so that the message points to the file(lineno)?
问题描述
为了将待办事项"项添加到我的代码中,我想在编译器输出中添加一条消息.
我希望它看起来像这样:
In order to add 'todo' items into my code, I want to put a message in the compiler output.
I would like it to look like this:
c:/temp/main.cpp(104): TODO - add code to implement this
为了利用Visual Studio构建输出功能,通过双击来导航到相应的行.
in order to make use of the Visual Studio build output functionality to navigate to the respective line by double-clicking it.
但是__LINE__
宏似乎扩展为int
,不允许写入
But the __LINE__
macro seems to expand to an int
, which disallows writing
#pragma message( __FILE__ "("__LINE__"): ..." )
还有其他方法吗?
推荐答案
以下是允许您单击输出窗格的一种:
Here is one that allows you to click on the output pane:
(那里还有其他一些不错的技巧)
(There are also some other nice tips there)
http://www.highprogrammer.com/alan/windev/visualstudio.html
// Statements like:
// #pragma message(Reminder "Fix this problem!")
// Which will cause messages like:
// C:\Source\Project\main.cpp(47): Reminder: Fix this problem!
// to show up during compiles. Note that you can NOT use the
// words "error" or "warning" in your reminders, since it will
// make the IDE think it should abort execution. You can double
// click on these messages and jump to the line in question.
#define Stringize( L ) #L
#define MakeString( M, L ) M(L)
#define $Line MakeString( Stringize, __LINE__ )
#define Reminder __FILE__ "(" $Line ") : Reminder: "
一旦定义,就这样使用:
Once defined, use like so:
#pragma message(Reminder "Fix this problem!")
这将创建如下输出:
C:\ Source \ Project \ main.cpp(47):提醒:解决此问题!
C:\Source\Project\main.cpp(47): Reminder: Fix this problem!
这篇关于如何使用#pragma message()以便消息指向文件(lineno)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!