繁体   English   中英

错误:标识符“cout”未定义。<iostream> 包含和使用命名空间 std;

[英]Error: Identifier “cout” is undefined. <iostream> included and using namespace std;

我试图cout一些变量,但编译器说cout is undefined 我已经包含了 iostream 并且正在使用命名空间 std。 删除using namespace stdusing 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;
    }
};

我正在尝试定义一个类,所以我的主要内容在其他地方。 运行一个非常基本的程序,只是 couts "hello world" 工作正常,问题特定于这段代码。

#include<iostream>放在第一位,顺序很重要

#include "Complex.h"
#include <iostream>
#include <cmath>

PS:为什么在使用“使用命名空间 std;”时使用 std::?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM