How can I use #pragma message() so that the message points to the file(lineno)?

前端 未结 6 888
一生所求
一生所求 2021-01-30 09:01

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 -         


        
6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 09:29

    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!") 
    

    This will create output like:

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

提交回复
热议问题