C++:为什么 std::greater<T>() 包含在 iostream 中?

C++: Why is std::greater<T>() included in iostream?

本文关键字:包含 iostream std 为什么 greater lt C++ gt      更新时间:2023-10-16

我注意到我的C++包含std::greater<T>()代码编译得很好,而不包含<functional>。这引起了我的思考。事实证明,这段代码编译:

#include <iostream>
int main(){
std::greater<T>();
}

但这个没有:

int main(){           //<iostream> doesn´t get included
std::greater<T>();
}

通过它,我可以推断<iostream>包含std::greater这对我来说似乎有些奇怪。有人可以解释一下,为什么std::greater<T>()包含在<iostream>中?

如果这很重要,我正在使用 g++(x86_64-posix-she-rev0,由 MinGW-W64 项目构建(8.1.0 和 C++14。

ISO标准不能保证。该标头的实现使用它。 您可能还会发现<utility><string>(可能作为<ios><iosfwd>的一部分包含在内(、<memory>和一些<type_traits>可以从<iostream>获得。

五个保证的标头是(自C++11以来(:ios,iosfwd,istream,ostream,streambuf。