[英]Error: Identifier “cout” is undefined. <iostream> included and using namespace std;
I am trying to cout
some variables but the compiler says that cout is undefined
.我试图
cout
一些变量,但编译器说cout is undefined
。 I have included iostream and am using namespace std.我已经包含了 iostream 并且正在使用命名空间 std。 Removing
using namespace std
and using std::cout
instead changes the issue to "namespace "std" has no member "cout" ".删除
using namespace std
并using std::cout
将问题更改为“命名空间“std”没有成员“cout”“。 I found some answers saying to add # include "stdafx.h"
to the code but Error: cannot open source file "stdafx.h"
occurs.我发现一些答案说在代码中添加
# include "stdafx.h"
但出现Error: cannot open source file "stdafx.h"
。
Code is:代码是:
#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;
}
};
I'm trying to define a class, so my main is elsewhere.我正在尝试定义一个类,所以我的主要内容在其他地方。 Running a very basic program that just couts "hello world" works fine, the problem is specific to this code.
运行一个非常基本的程序,只是 couts "hello world" 工作正常,问题特定于这段代码。
Put #include<iostream>
at the first position, the order is important把
#include<iostream>
放在第一位,顺序很重要
#include "Complex.h"
#include <iostream>
#include <cmath>
PS: Why do you use std:: when you are using "using namespace std;"? PS:为什么在使用“使用命名空间 std;”时使用 std::?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.