indipendent output

S

salvo

Hi,

I made a little program in C++, which initially displayed its data to the
standard output with the cout object. Now that I added a little graphic
interface with gtk+, I'd like to keep the class code as indipendent as
possible. This way, I could leave both version, graphic and not.

In the graphic version, every object would output its data to the
text_view object, while in the no-graphic version, it would output its
data to the standard output with cout. How can I do this ?

Any suggestions?

Thanks in advance
Salvo
 
T

Thomas Matthews

salvo said:
Hi,

I made a little program in C++, which initially displayed its data to the
standard output with the cout object. Now that I added a little graphic
interface with gtk+, I'd like to keep the class code as indipendent as
possible. This way, I could leave both version, graphic and not.

In the graphic version, every object would output its data to the
text_view object, while in the no-graphic version, it would output its
data to the standard output with cout. How can I do this ?

Any suggestions?

Thanks in advance
Salvo

Yes, derive a class from streambuf which will write
to the UI. An instance of this class can be passed
around wherever an ostream class is required.

Read the FAQs and welcome.txt for guidelines. Also
search the web for Dietmar Kuhl, who is an expert
in this area. His website contains an example of
creating a specialized stream class.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
S

salvo

Yes, derive a class from streambuf which will write
to the UI. An instance of this class can be passed
around wherever an ostream class is required.

Read the FAQs and welcome.txt for guidelines. Also
search the web for Dietmar Kuhl, who is an expert
in this area. His website contains an example of
creating a specialized stream class.

Thank you! It seems to be exactly what I needed.

Salvo
 

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

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,652
Latest member
Campbellamy

Latest Threads

Top