C++17之判斷有無包含某文件
- 2020 年 2 月 24 日
- 筆記
使用
__has_include
來判斷有無包含某文件。
主要作用是在編譯時候判斷該系統環境是否存在某個文件,如果不存在則使用其他文件替代,以提高兼容性。
簡單例子
int main(int argc, char **argv) { #if __has_include(<iostream>) std::cout << "Hello world!" << std::endl; #else printf("Hello world!"); #endif return 0; }