原始 KB 编号:
  
  243444
  
  
  
   例如,尝试使用命名空间
   
    std
   
   (从 STD C++ 库标头
   
    <cstdlib>
   
   引用函数,
   
    std::exit(0)
   
   ) 会导致编译器发出 C2653 或 C2039 (,具体取决于是否在发出错误) 错误消息时定义命名空间
   
    std
   
   。
  
  
   <cstdlib>
  
  不定义命名空间
  
   std
  
  。 这与 Visual C++ 文档相反,该文档指出:
  
  
  
   包括标准标头
   
    <cstdlib>
   
   ,以有效地将标准标头
   
    <stdlib.h>
   
   包含在命名空间中
   
    std
   
   。
  
  
   若要解决此问题,请将 放在
   
    #include <cstdlib>
   
   命名空间
   
    std
   
   中。
  
  
   尝试编译以下内容将导致编译器显示以下错误:
  
  
   错误 C2653: 'std' : 不是类或命名空间名称
  
  // Compile Options: /GX
#include <cstdlib>
void main()
    std::exit(0);
但是,尝试编译以下内容会导致编译器显示以下错误:
错误 C2039: “exit” : 不是 “std” 的成员
// Compile Options: /GX
#include <vector>
#include <cstdlib>
void main()
    std::exit(0);
在第一种情况下,显示 C2653,因为尚未定义命名空间 std 。 第二种情况显示 C2039,因为命名空间 std 已在标头 <vector>) 中 (定义,但函数 exit 不是该命名空间的一部分。 若要在任一情况下解决此问题,只需将 括 #include <cstdlib> 在命名空间 std中,如下所示:
// Compile Options: /GX
namespace std
    #include <cstdlib>
void main()
    std::exit(0);