【发布时间】:2015-05-21 02:48:30
【问题描述】:
我正在尝试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;
}
};
我正在尝试定义一个类,所以我的主要在别处。 运行一个非常基本的程序,只输出“hello world”就可以了,问题是这段代码特有的。
【问题讨论】: