代码使用命名空间运行,但不使用 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 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,则代码运行良好。
setw
、fixed
、setprecision
和 left
也在 std
命名空间中,因此您还需要为所有这些命名空间添加using
指令。
相关文章:
- 为什么std::async使用同一个线程运行函数
- 在声明中合并两个常量"std::set"(不是在运行时)
- C++中 std::map 的运行时复杂度是多少?
- C++在使用std::multimap时出现运行时错误的几率很小
- std::tuple 可以根据其值在编译时/运行时排序吗?
- 为什么我使用 std::copy() 收到运行时错误(分段错误)?
- 如何创建一个模板化函数,可以在任何具有字符串键的 std::map 上运行?
- std::bad_alloc运行时异常
- std::copy 导致运行时检查失败 #2
- 使用 (cin) 用户输入将其粘贴到 std::system 中,并在另一个终端中运行带有输入的命令
- 在运行之前获取 std::thread's thread:id?
- CLang:在 std::thread 中运行函数会导致结构创建BAD_ACCESS
- 使用-static libstdc++时std::线程弱,因此在运行时会导致崩溃
- 编译了一个recent-C++.因此,如果没有暴露std符号,请在旧系统上运行
- 运行 std::线程不在构造函数中
- 在运行时,何时完全初始化 std 库才能在不破坏代码的情况下使用它?
- 多线程中的 std::basicstring 的运行时分段错误C++点燃进程
- std :: list(双重链接列表)未知运行时错误
- 编译器发射std :: move()运行时调用
- 为什么用空函数运行std::线程会花费大量内存