我有一个相当大的应用程序,而且我没有使用std命名空间。我注意到我没有包含std::cos或std::sin,但我得到了正确的结果。为什么?
以下是一些简化代码示例:
#include <ctime>
#include <cmath>
#include <iostream>
#include <vector>
//#include <unistd.h>
#include <fstream>
#include <sstream>
#include <iomanip>
using std::cout;
using std::endl;
int main()
{
double pi = 4*(atan(1));
cout << "pi = " << pi << endl
<< "cos(pi) = " << cos(pi) << endl
<< "sin(pi) = " << sin(pi) << endl;
return 0;
}
我已经保留了所有的头文件,在主代码中使用它们。输出结果返回了 ~3.14、-1 和 1e-16,这是预期的。为什么会这样呢?cos和sin不是在std里嘛?
我正在远程Unix服务器上使用g++编译器。
谢谢。