#pragma message("Insert User-defined Information here!")
但是這樣沒有文件和行數信息,不能定位。
使用如下方式可以定位:
- // put the following code in header file or at the beginning of the source file.
- #define __STR2__(x) #x
- #define __STR1__(x) __STR2__(x)
- #define __LOC__ __FILE__ "("__STR1__(__LINE__)") : Warning Msg: "
- // output the user-define information in the source file.
- #pragma message(__LOC__"User-defined Information")
// put the following code in header file or at the beginning of the source file.
#define __STR2__(x) #x
#define __STR1__(x) __STR2__(x)
#define __LOC__ __FILE__ "("__STR1__(__LINE__)") : Warning Msg: "
// output the user-define information in the source file.
#pragma message(__LOC__"User-defined Information")
參考:http://support.microsoft.com/kb/155196/en-us