Buc*_*val 3 c++ cout undefined
我正在尝试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;
}
};
Run Code Online (Sandbox Code Playgroud)
我正在尝试定义一个类,所以我的主要课程在其他地方。运行一个仅会提示“ hello world”的非常基本的程序即可正常工作,该问题特定于此代码。
将#include<iostream>在第一位置,顺序很重要
#include "Complex.h"
#include <iostream>
#include <cmath>
Run Code Online (Sandbox Code Playgroud)
PS:为什么在使用“使用命名空间std;”时使用std ::?
| 归档时间: |
|
| 查看次数: |
13694 次 |
| 最近记录: |