Plex
Plex

Reputation: 75

c++ error message ostream does not name a type

I use c++ to learn about classes and streams but every time I try I get the error ostream does not name a type I use std namespace, include iostream, include 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);
}

uhr.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);

Error: uhr.h:14:2: error: ‘ostream’ does not name a type ostream& print(ostream & o) const; ^ uhr.h:17:2: error: ‘ostream’ does not name a type ostream& operator << (ostream &o,const Uhr& u);

Upvotes: 0

Views: 6175

Answers (1)

Yousaf
Yousaf

Reputation: 29282

In the header file uhr.h, change

ostream& print(ostream & o);

to

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

Upvotes: 2

Related Questions