owa*_*ake 5 c++ gcc codeblocks
为什么我不需要包含cstdlib以及如何禁用它?我在Windows 7上使用Code :: Blocks with GCC编译器.
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "Hello" << endl;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
您不需要包括<cstdlib>因为它(或其中包含的部分system())包含在内<iostream>.未指定标准标头是否包含或包含哪些其他(标准)标头.您无法禁用此行为,但应注意它以避免不同标准库实现之间的可移植性问题.
你不应该依赖这种行为并包括<cstdlib>你自己.您还应该使用std::system而不是全局system.<c*>标头中的函数只能保证在std命名空间中(全局的,另一方面,在<*.h>标题中).