代码使用命名空间运行,但不使用 std::cout 运行

Code runs with namespace but not with using std::cout

本文关键字:运行 std cout 命名空间 代码      更新时间:2023-10-16
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
int main()
{
  double degrees, radians;
  const double PI = 3.14159;
  cout << "Enter an angle in degrees and I will convert itn";
  cout << "to radians for you: ";
  cin >> degrees;
  radians = degrees * PI / 180;
  cout << degrees << " degrees is equal to ";
  cout << fixed << showpoint << setprecision(4);
  cout << left << setw(7) << radians << "radians.n ";
  return 0;
}

当我编译时,我收到多个与未声明的操纵器相关的错误,但我在顶部有 #include 指令。但是,如果我将使用 std:: 行替换为仅使用 namespace:std,则代码运行良好。

setwfixedsetprecisionleft 也在 std 命名空间中,因此您还需要为所有这些命名空间添加using指令。