[英]Is there a way to reference cout without using namespace std or prefixing with std::?
[英]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 ::行,則代碼運行良好。
setw
, fixed
, setprecision
和left
也在std
命名空間中,因此您也需要為所有它們添加using
指令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.