Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.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
toupper属于哪个名称空间 当我在阅读初学者的C++代码时,我对ToupPube在以下行中的用法感到困惑: std::transform(data.begin(), data.end(), data.begin(), ::toupper);_C++_Namespaces - Fatal编程技术网

toupper属于哪个名称空间 当我在阅读初学者的C++代码时,我对ToupPube在以下行中的用法感到困惑: std::transform(data.begin(), data.end(), data.begin(), ::toupper);

toupper属于哪个名称空间 当我在阅读初学者的C++代码时,我对ToupPube在以下行中的用法感到困惑: std::transform(data.begin(), data.end(), data.begin(), ::toupper);,c++,namespaces,C++,Namespaces,从上面的一行中,我知道“transform”来自名称空间std,但我不知道toupper来自哪个名称空间。也许C++有一个默认的命名空间 那只是我的猜测。那么你能在这里向我解释一下toupper的用法吗?如果你包括 <cctype> <ctype.h> 那么toupper()位于命名空间std中。如果包括 <cctype> <ctype.h> 然后toupper()位于全局命名空间中。(如果未在特定名称空间中定义,则所有内容都以该名

从上面的一行中,我知道“transform”来自名称空间std,但我不知道toupper来自哪个名称空间。也许C++有一个默认的命名空间 那只是我的猜测。那么你能在这里向我解释一下toupper的用法吗?

如果你包括

<cctype>
<ctype.h>

那么toupper()位于命名空间std中。如果包括

<cctype>
<ctype.h>

然后toupper()位于全局命名空间中。(如果未在特定名称空间中定义,则所有内容都以该名称空间结束。当您在特定名称空间中时,以前导的
引用的名称空间。)


同样的规则适用于
等。

如果您对::toupper语法感到困惑,它会告诉您,在这种情况下,函数位于全局命名空间中。您总是可以在名称前加上一个双冒号,这将告诉编译器检入全局名称空间,而不是从内部名称空间向外搜索

void foo() { std::cout << "global"; }
namespace inner {
   void foo() { std::cout << "inner"; }
   void call() {
      foo();   // prints inner
      ::foo(); // prints global
      ::inner::foo(); // prints inner (fully qualified namespace)
   }
}
void foo(){std::cout