📄 preprocessor_if.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>#if, #ifdef, #ifndef, #else, #elif, #endif</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">C/C++ Pre-processor Commands</a> > <a href= "preprocessor_if.html">#if, #ifdef, #ifndef, #else, #elif, #endif</a> </div> <div class="name-format"> #if, #ifdef, #ifndef, #else, #elif, #endif </div> <p>These commands give simple logic control to the compiler. As a file is being compiled, you can use these commands to cause certain lines of code to be included or not included.</p> <pre class="example-code"> #if expression </pre> <p>If the value of expression is true, then the code that immediately follows the command will be compiled.</p> <pre class="example-code"> #ifdef macro </pre> <p>If the <em>macro</em> has been defined by a <a href= "define.html">#define</a> statement, then the code immediately following the command will be compiled.</p> <pre class="example-code"> #ifndef macro </pre> <p>If the <em>macro</em> has not been defined by a <a href= "define.html">#define</a> statement, then the code immediately following the command will be compiled.</p> <p>A few side notes: The command #elif is simply a horribly truncated way to say "elseif" and works like you think it would. You can also throw in a "defined" or "!defined" after an #if to get added functionality.</p> <div class="related-examples-format"> Example code: </div> <div class="related-examples"> <p>Here's an example of all these:</p> <pre class="example-code"> #ifdef DEBUG cout << "This is the test version, i=" << i << endl; #else cout << "This is the production version!" << endl; #endif </pre> <p>You might notice how that second example could make debugging a lot easier than inserting and removing a million "cout"s in your code.</p> </div> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="define.html">#define</a> </div> </div> </td> </tr> </table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -