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

前端 未结 6 890
一生所求
一生所求 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:48

    On Visual C++ you can just do

    #pragma message(__FILE__ "(" _CRT_STRINGIZE(__LINE__) ")" ": warning: [blah]")
    

    _CRT_STRINGIZE is often already defined in some header, but if it's not, you can define it:

    #define _CRT_STRINGIZE_(x) #x
    #define _CRT_STRINGIZE(x) _CRT_STRINGIZE_(x)
    

提交回复
热议问题