#pragma

Ethereal / 2024-03-11 / 原文

\(reference\)
\(pragma\),希腊文,意思是“行动”,“实践”的意思,它是 C/C++ 的预处理命令
用法示例:
message:在编译信息输出窗口中输出相应的信息。

#include <iostream>
#pragma message("This is a test!")
int main() {
    std::cout << "Hello,World" << std::endl;
    return 0;
}

输出:

g++ test.cpp -o app
test.cpp:2:34: note: '#pragma message: This is a test!'
    2 | #pragma message("This is a test!")
      |                                  ^
./app
Hello,World

可以发现,\(pragma\) 输出的 messagemain 函数执行之前完成