C++错误消息ostream未命名类型

标签 c++ iostream

我使用 C++ 来了解类和流,但每次我尝试时都会得到错误 ostream does not name a type 我使用 std 命名空间,包括 iostream,包括 header

Uhr.cpp

#include<iostream>
#include"uhr.h"

using namespace std;

Uhr::Uhr(int Stunde, int Minute, int Sekunde){
this -> Stunde = Stunde;
this -> Minute = Minute;
this -> Sekunde = Sekunde;
}


void Uhr::setTime(int Stunde, int Minute, int Sekunde)
{
 this -> Stunde = Stunde;
 this -> Minute = Minute;
 this -> Sekunde = Sekunde;
}

void Uhr::setOne()
{
this -> Sekunde=+Sekunde;
}

ostream& Uhr::print(ostream& o)
{
o = "Stunden " << Stunden << " Minuten " << Minuten <<" Sekunden" << Sekunden;
return o:   
}

ostream& operator << (ostream &o,const Uhr& u)
{
 return u.print(o);
}

呃.h

#include<iostream>

class Uhr
{
private:
int Stunde;
int Minute;
int Sekunde;

public:
Uhr(int Stunde = 0, int Minute = 0, int Sekunde = 0);
void setTime(int Stunde, int Minute, int Sekunde);
void setOne();
ostream& print(ostream & o);
};

ostream& operator << (ostream &o,const Uhr& u);

错误: uhr.h:14:2: 错误:“ostream”没有命名类型 ostream & 打印(ostream & o)常量; ^ uhr.h:17:2: 错误:“ostream”没有命名类型 ostream& operator << (ostream &o,const Uhr& u);

最佳答案

在头文件uhr.h中,改

ostream& print(ostream & o);

std::ostream& print(std::ostream & o);

关于C++错误消息ostream未命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42058922/

相关文章:

c++ - iostream 的问题,我的输出 endl 是小方 block

c++ - 有没有一种 C++ 方法可以使用 iostream 来格式化地址和指针?

javascript - Emstripten 可以编译 iostream 库吗?

c++ - 为什么fstream不是继承自c++中的ifstream和ofstream?

c++ - 如何加载具有负高度的图像

c++ - LeapMotion、Qt 和信号

c++ - 将特定指针转换为 std::any 指针

c++ - 如何隐藏exe或dll中的字符串?

c++ - 修复关于 C/C++ 和寄存器访问的知识差距

c++ - 如何使用 Boost IOStreams 的 Gzip 文件接口(interface)逐行读取?