How to return stdout from a method ?

  • Thread starter barthelemy.von.haller
  • Start date
B

barthelemy.von.haller

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::eek:stream*' in return
// return cout; // this returns : invalid conversion from
`void*' to `std::eek: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
 
D

Daniel Kraft

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::eek:stream*' in return
// return cout; // this returns : invalid conversion from
`void*' to `std::eek: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
 
B

barthelemy.von.haller

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

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

Barth
 
D

Darío Griffo

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::eek:stream& getDebugStream()
{
return std::cout;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top