Reputation: 33
I am trying to cout
some variables but the compiler says that cout is undefined
. I have included iostream and am using namespace std. Removing using namespace std
and using std::cout
instead changes the issue to "namespace "std" has no member "cout" ". I found some answers saying to add # include "stdafx.h"
to the code but Error: cannot open source file "stdafx.h"
occurs.
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.
Upvotes: 3
Views: 21655
Reputation: 20372
Put #include<iostream>
at the first position, the order is important
#include "Complex.h"
#include <iostream>
#include <cmath>
PS: Why do you use std:: when you are using "using namespace std;"?
Upvotes: 4