RichEdit & Streams

  • Thread starter news.tkdsoftware.com
  • Start date
N

news.tkdsoftware.com

How would one go about connecting std::cout to a CRichEditCtrl object?

--
 
J

John Harrison

news.tkdsoftware.com said:
How would one go about connecting std::cout to a CRichEditCtrl object?

You need to derive a class from std::streambuf that outputs to a
CRichEditCtrl object. Then you replace the stream buffer that std::cout has
with your derived buffer.

class RichEditControlBuffer : public std::streambuf
{
...
};

int main()
{
RichEditControlBuffer my_buffer;
std::streambuf* old_buffer = std::cout.rdbuf(&my_buffer);
// now std::cout is connected to your buffer;
...
std::cout(old_buffer); // restore the old buffer before you quit
}

Writing the RichEditControlBuffer class is not a trivial task. You need a
good book, like The C++ Standard Library by Josuttis.

john
 
M

Mike Wahler

John Harrison said:
You need to derive a class from std::streambuf that outputs to a
CRichEditCtrl object. Then you replace the stream buffer that std::cout has
with your derived buffer.

class RichEditControlBuffer : public std::streambuf
{
...
};

int main()
{
RichEditControlBuffer my_buffer;
std::streambuf* old_buffer = std::cout.rdbuf(&my_buffer);
// now std::cout is connected to your buffer;
...
std::cout(old_buffer); // restore the old buffer before you quit
}

Writing the RichEditControlBuffer class is not a trivial task. You need a
good book, like The C++ Standard Library by Josuttis.

Equally, if not more useful for this would be the Langer & Kreft book.

-Mike
 

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,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top