gpt4 book ai didi

c++ - 如何使用#pragma message() 使消息指向文件(lineno)?

转载 作者:IT老高 更新时间:2023-10-28 12:41:13 27 4
gpt4 key购买 nike

为了在我的代码中添加“待办事项”项,我想在编译器输出中添加一条消息。
我希望它看起来像这样:

c:/temp/main.cpp(104): TODO - add code to implement this

为了利用 Visual Studio 构建输出功能通过双击导航到相应的行。

__LINE__ 宏似乎扩展为一个 int,不允许写入

#pragma message( __FILE__ "("__LINE__"): ..." )

还有其他方法吗?

最佳答案

这是一个允许您单击输出 Pane 的工具:

(那里还有其他一些不错的提示)

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: "

一旦定义,像这样使用:

#pragma message(Reminder "Fix this problem!") 

这将创建如下输出:

C:\Source\Project\main.cpp(47): Reminder: Fix this problem!

关于c++ - 如何使用#pragma message() 使消息指向文件(lineno)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5966594/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com