PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > How to return stdout from a method ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to return stdout from a method ?

Réponse
 
LinkBack Outils de la discussion
Vieux 30/06/2008, 10h57   #1
barthelemy.von.haller@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to return stdout from a method ?

Hi,

I am trying to return the standard output from a method like that :

ostream *XXX::GetDebugStream() {
// return debugFile; // I don't want that, but it works
// return stdout; // this returns : error: cannot convert
`_IO_FILE*' to `std:stream*' in return
// return cout; // this returns : invalid conversion from
`void*' to `std:stream*'
}

I tried to return stdout or cout but it doesn't work. I understand why
it doesn't work with cout but not with stdout.

Could someone explain me what I am doing wrong ?

Thanks in advance

Barth
  Réponse avec citation
Vieux 30/06/2008, 11h51   #2
Daniel Kraft
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to return stdout from a method ?

barthelemy.von.haller@gmail.com wrote:
> Hi,
>
> I am trying to return the standard output from a method like that :
>
> ostream *XXX::GetDebugStream() {
> // return debugFile; // I don't want that, but it works
> // return stdout; // this returns : error: cannot convert
> `_IO_FILE*' to `std:stream*' in return
> // return cout; // this returns : invalid conversion from
> `void*' to `std:stream*'
> }
>
> I tried to return stdout or cout but it doesn't work. I understand why
> it doesn't work with cout but not with stdout.


try
return &cout;

cout is not a pointer, thus you will have to take the address of it; and
stdout is not a C++ ostream class but rather a FILE* you can use with
fprintf and friends.

Daniel

> Could someone explain me what I am doing wrong ?
>
> Thanks in advance
>
> Barth



--
Done: Bar-Sam-Val-Wiz, Dwa-Elf-Hum-Orc, Cha-Law, Fem-Mal
Underway: Ran-Gno-Neu-Fem
To go: Arc-Cav-Hea-Kni-Mon-Pri-Rog-Tou
  Réponse avec citation
Vieux 30/06/2008, 12h29   #3
barthelemy.von.haller@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to return stdout from a method ?

On 30 juin, 12:51, Daniel Kraft <d...@domob.eu> wrote:
> barthelemy.von.hal...@gmail.com wrote:
> > Hi,

>
> > I am trying to return the standard output from a method like that :

>
> > ostream *XXX::GetDebugStream() {
> > // return debugFile; // I don't want that, but it works
> > // return stdout; // this returns : error: cannot convert
> > `_IO_FILE*' to `std:stream*' in return
> > // return cout; // this returns : invalid conversion from
> > `void*' to `std:stream*'
> > }

>
> > I tried to return stdout or cout but it doesn't work. I understand why
> > it doesn't work with cout but not with stdout.

>
> try
> return &cout;
>
> cout is not a pointer, thus you will have to take the address of it; and
> stdout is not a C++ ostream class but rather a FILE* you can use with
> fprintf and friends.
>
> Daniel
>
> > Could someone explain me what I am doing wrong ?

>
> > Thanks in advance

>
> > Barth

>
> --
> Done: Bar-Sam-Val-Wiz, Dwa-Elf-Hum-Orc, Cha-Law, Fem-Mal
> Underway: Ran-Gno-Neu-Fem
> To go: Arc-Cav-Hea-Kni-Mon-Pri-Rog-Tou


Thank you very much, it works. I don't know why I was so sure that
cout was a pointer...

Barth
  Réponse avec citation
Vieux 30/06/2008, 13h09   #4
Darío Griffo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to return stdout from a method ?

On Jun 30, 8:29 am, barthelemy.von.hal...@gmail.com wrote:
> On 30 juin, 12:51, Daniel Kraft <d...@domob.eu> wrote:
>
>
>
> > barthelemy.von.hal...@gmail.com wrote:
> > > Hi,

>
> > > I am trying to return the standard output from a method like that :

>
> > > ostream *XXX::GetDebugStream() {
> > > // return debugFile; // I don't want that, but it works
> > > // return stdout; // this returns : error: cannot convert
> > > `_IO_FILE*' to `std:stream*' in return
> > > // return cout; // this returns : invalid conversion from
> > > `void*' to `std:stream*'
> > > }

>
> > > I tried to return stdout or cout but it doesn't work. I understand why
> > > it doesn't work with cout but not with stdout.

>
> > try
> > return &cout;

>
> > cout is not a pointer, thus you will have to take the address of it; and
> > stdout is not a C++ ostream class but rather a FILE* you can use with
> > fprintf and friends.

>
> > Daniel

>
> > > Could someone explain me what I am doing wrong ?

>
> > > Thanks in advance

>
> > > Barth

>
> > --
> > Done: Bar-Sam-Val-Wiz, Dwa-Elf-Hum-Orc, Cha-Law, Fem-Mal
> > Underway: Ran-Gno-Neu-Fem
> > To go: Arc-Cav-Hea-Kni-Mon-Pri-Rog-Tou

>
> Thank you very much, it works. I don't know why I was so sure that
> cout was a pointer...
>
> Barth


Did you tried returning the reference, instead of a pointer?
Just like the << operator?

std:stream& getDebugStream()
{
return std::cout;
}
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h59.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13427 seconds with 12 queries