天天看點

#pragma message 官方文檔翻譯

一 作用

Sends a string literal to the standard output without terminating the compilation.

在不終止編譯的情況下将字元串字面量發送到标準輸出

二 文法

#pragma message( message-string )

三 備注

A typical use of the message pragma is to display informational messages at compile time.

The message-string parameter can be a macro that expands to a string literal, and you can concatenate such macros with string literals in any combination.

If you use a predefined macro in the message pragma, the macro should return a string. Otherwise, you'll have to convert the output of the macro to a string.

The following code fragment uses the message pragma to display messages during compilation:

翻譯:message pragma的一個典型應用是在編譯時顯示資訊消息。

message-string參數可以是一個宏擴充為一個字元串字面量,你可以以任何形式組合宏和字元串字面量。

如果在message pragma中預定義宏,該宏必須傳回一個字元串,否則你必須将宏的輸出轉換為字元串。以下片段使用message pragma在編譯過程中顯示消息。

// pragma_directives_message1.cpp
// compile with: /LD
#if _M_IX86 >= 500
#pragma message("_M_IX86 >= 500")
#endif

#pragma message("")

#pragma message( "Compiling " __FILE__ )
#pragma message( "Last modified on " __TIMESTAMP__ )

#pragma message("")

// with line number
#define STRING2(x) #x
#define STRING(x) STRING2(x)

#pragma message (__FILE__ "[" STRING(__LINE__) "]: test")

#pragma message("")
           

四 原文

官方文檔