Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ if/endif预处理指令_C++_C_Preprocessor Directive - Fatal编程技术网

C++ if/endif预处理指令

C++ if/endif预处理指令,c++,c,preprocessor-directive,C++,C,Preprocessor Directive,我应该始终使用if指令和endif吗 如果是-如果我只使用If,会有什么问题? 如果否-何时仅使用If,何时组合If/else? 谢谢。是的 如果没有endif,预处理器将无法知道if块的结尾。如果没有匹配的endif,或者。。。endif您的代码将无法编译 1.If yes - what could be a problem if I only use #if? 正如其他人所提到的,如果只使用if,并且与endif不匹配,预处理器将失败,并显示为编译器错误 2.If no - why I u

我应该始终使用if指令和endif吗

如果是-如果我只使用If,会有什么问题? 如果否-何时仅使用If,何时组合If/else? 谢谢。是的


如果没有endif,预处理器将无法知道if块的结尾。

如果没有匹配的endif,或者。。。endif您的代码将无法编译

1.If yes - what could be a problem if I only use #if?
正如其他人所提到的,如果只使用if,并且与endif不匹配,预处理器将失败,并显示为编译器错误

2.If no - why I use only #if,and when combination #if/#else?
即使在if/else的情况下,末尾也应该有endif。否则它将无法工作。你可以自己试试看

除了检查和定义宏之外,它们最常用于条件编译。请在下面找到一些基本级别的相关链接:


ifand endif不是宏,而是预处理指令。我无法想象你为什么认为这是一个问题。你有没有遇到过这样一种情况:省略endif看起来很有用?另外,我不明白你的第二个问题。你是说什么时候而不是为什么?