简体   繁体   English

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

[英]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 stdusing 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.

相关问题 #include<iostream> 存在,但出现错误:标识符“cout”未定义。 为什么? - The #include<iostream> exists, but I get an error: identifier "cout" is undefined. Why? 错误:&#39;cout&#39;:未声明的标识符; 虽然我在程序中包含了iostream头文件 - Error: 'cout' : undeclared identifier; though I've included iostream header file in program 为什么我得到错误“&#39;cout&#39;在命名空间&#39;std&#39;中没有命名类型”当我使用“使用cout = std :: cout;”? - Why do I get error “'cout' in namespace 'std' does not name a type” when I use “using cout = std::cout;”? 错误“未定义对‘std::cout’的引用” - Error "undefined reference to 'std::cout'" Netbeans:找不到包含文件 <iostream> ,也无法解析标识符std,cout - Netbeans: cannot find include file <iostream>, also, unable to resolve identifier std, cout 代码使用命名空间运行,但不使用std :: cout运行 - Code runs with namespace but not with using std::cout 可以“使用命名空间标准;” 和“std::cout”一起使用? - can "using namespace std;" and "std::cout" be used together? 有没有办法在不使用命名空间std或使用std ::前缀的情况下引用cout? - Is there a way to reference cout without using namespace std or prefixing with std::? 将SQLite与std :: iostream一起使用 - Using SQLite with std::iostream iostream 和命名空间 std 之间是什么关系? - What is the relationship between iostream and namespace std?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM