使用isalpha函数时不需要std命名空间

Lan*_*AOH 0 c++ namespaces using std

我是C++的初学者.据我所知,为了使用名称,我们必须包含由该名称组成的库.此后,我们可以预先添加命名空间的名称或使用using关键字.

例如

不使用关键字:

std::cout << "Hello Word!" << std::endl;
Run Code Online (Sandbox Code Playgroud)

使用关键字:

using namespace std;
cout << "Hello World!" << endl;
Run Code Online (Sandbox Code Playgroud)

我在网上看到了一个使用isalpha名称空间中locale库名称的在线代码示例std.但是,该样本不使用上述任何方法.

例如

#include <iostream>
#include <locale>
int main() {
  std::cout << isalpha('a') << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释为什么代码仍然有效吗?

Ker*_* SB 5

当您为C库工具包含C++头时,即<cfoo>对应于C头的头时<foo.h>,C库中的名称将在命名空间中声明std.但是,另外未指定名称是否也在全局名称空间中声明.

在你的情况下,它们似乎是.但是你不能依赖它,你也不应该.