错误:标识符"cout"未定义。<iostream> 包含并使用命名空间 std;
Error: Identifier "cout" is undefined. <iostream> included and using namespace std;
我正在尝试cout
一些变量,但编译器说是cout is undefined
。我已经包含了iostream,并且正在使用命名空间std。删除using namespace std
和using std::cout
会将问题更改为"命名空间std没有成员cout"。我找到了一些答案,说要将# include "stdafx.h"
添加到代码中,但出现了Error: cannot open source file "stdafx.h"
。
代码为:
#include "Complex.h"
#include <cmath>
#include <iostream>
using namespace std;
Complex::Complex(int PolarOrRectang, float RealOrArg, float ImagOrAng) {
if (PolarOrRectang == 0) {
real = RealOrArg;
imag = ImagOrAng;
else {
real = RealOrArg * cos(ImagOrAng);
imag = RealOrArg * sin(ImagOrAng);
}
};
void Complex::getValue(int PolarOrRectang) {
if (PolarOrRectang == 0) {
cout << real << " +_" << imag << "i" << endl;
} else {
cout << sqrt((real^2) + (imag^2)) << "*e^-" << atan(imag / real)<< endl;
}
};
我正在尝试定义一个类,所以我的main在别处。运行一个只定制"helloworld"的非常基本的程序可以很好地工作,问题是这个代码特有的。
将#include<iostream>
放在第一个位置,订单是重要的
#include "Complex.h"
#include <iostream>
#include <cmath>
PS:当你使用"使用命名空间std;"时,为什么要使用std:?
相关文章:
- 为什么std::copyable包含std::moveable
- 包含 std::list 的结构体的 C++ 初始化
- C++如何乘以包含 std::variant 元素的向量的迭代器?正在执行迭代器类型的转换?
- 包含 std::threads 的元素向量
- std::包含 std::函数回调的多个包装器的向量不起作用
- 检查 std::any 变量是否包含 std::string 时出现问题
- 安装 GCC 7.1 是否会在标准库中包含 std::is_base_of_v
- C++ 中的 NAPI 本机模块正在部分执行(包含 std::thread)
- 包含 std::string 常量的类
- 即使在包含 std 命名空间之后,fstream 在 Visual Studio 2017 中也无法正常工作
- 如何重用包含 std::ifstream 的类
- 提升序列化:SIGABRT 同时反序列化包含 std::shared_ptr 的对象上的 boost::shared_p
- 传统C 代码不包含std ::前缀
- 如何在(C )构造函数参数列表中包含std:列表
- 从C++文件中读取包含 std::vector 的对象
- 在头文件中包含std::vector会导致模板实例化错误
- 是否有一个包含std::unique_ptr的c++标准库实现可以与visualstudio2008一起使用
- 包含 std::forward 会产生错误,但其省略会编译.为什么
- 包含std ::队列的类的价值限制
- 为什么结构make_unique在包含 std::p romise 作为成员时失败?