C++ 头文件保护符

  头文件保护符用 #ifdef 和 #ifndef ,检查结果为真时, 执行后续操作直至遇到#endif指令。

  // 代码取自 C++ primer 第五版

  #ifndef SALES_DATA_H

  #define SALES_DATA_H

  #include<string>

  struct Sales_data{

    std::string bookNO;

    unsigned units_sold = 0 ;

    double revenue = 0.0;

  };

  #endif

  在 #ifndef 检查为真时,一直执行到定义完结构体到 #endif 为止。

原文地址:https://www.cnblogs.com/wshr007/p/10439595.html