簡體   English   中英

代碼使用命名空間運行,但不使用std :: cout運行

[英]Code runs with namespace but not with using std::cout

#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 it\n";
  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指令的頂部。 但是,如果我僅使用namespace:std替換了using std ::行,則代碼運行良好。

setwfixedsetprecisionleft也在std命名空間中,因此您也需要為所有它們添加using指令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM