Click here to Skip to main content
15,908,901 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Joaquín M López Muñoz20-May-03 11:58
Joaquín M López Muñoz20-May-03 11:58 
GeneralVector & structur Pin
aguest20-May-03 0:58
aguest20-May-03 0:58 
GeneralRe: Vector & structur Pin
markkuk20-May-03 1:23
markkuk20-May-03 1:23 
GeneralRe: Vector & structur Pin
aguest20-May-03 12:02
aguest20-May-03 12:02 
GeneralRe: Vector & structur Pin
markkuk20-May-03 12:31
markkuk20-May-03 12:31 
GeneralRe: Vector & structur Pin
aguest20-May-03 14:36
aguest20-May-03 14:36 
GeneralRe: Vector & structur Pin
markkuk21-May-03 1:25
markkuk21-May-03 1:25 
GeneralWriting my own stream class Pin
Patje19-May-03 22:12
Patje19-May-03 22:12 
For a module I want to write my own stream class.
Although not identical the following example illustrates what I want to do:
suppose you have a class representing a printer:
class Printer { ...};

I want the user of this class to send data to this class using the << operator, so that any data type/class, for which << is defined on streams, e.g.
Printer myPrinter (printerName);
PrinterStream &printStr = myPrinter.getStream();
printStr << "Hello world" << 123 << std::endl;

So, how can I write my own stream class so that I can intercept the data send to printStr?
I probably need to inherit from some STL stream class, but I don't know where to start. Is this something that can be done easily, or is this almost impossible?

Another alternative (although I don't really like it) is to let my getStream() method to return a stringstream. My class then simply needs a kind of flush method to get the data from the stringstream, send it to the output where I want it and then empty the stringstream. I don't like this alternative because it exposes the fact that's a stringstream to the caller. Also I cannot add my own output manipulators (e.g. to set the font or color) to the stream.

Does anybody know a simple solution, or point me to an article that explains how to write your own stream class?

Thanks in advance.

Enjoy life, this is not a rehearsal !!!

My Articles:
- Implementing a Subject/Observer pattern with templates
- Different ways of writing class factories
- AutoRunner: a template class to automatically run start- and cleanup-code in code blocks
</

GeneralRe: Writing my own stream class Pin
cerez0220-May-03 5:15
cerez0220-May-03 5:15 
GeneralRe: Writing my own stream class Pin
Joaquín M López Muñoz20-May-03 10:28
Joaquín M López Muñoz20-May-03 10:28 
GeneralRe: Writing my own stream class Pin
Patje20-Jun-03 3:50
Patje20-Jun-03 3:50 
Generalvector troubles Pin
aguest19-May-03 4:30
aguest19-May-03 4:30 
GeneralRe: vector troubles Pin
Joaquín M López Muñoz19-May-03 6:42
Joaquín M López Muñoz19-May-03 6:42 
GeneralInsert icons into ListView Pin
User 1605519-May-03 4:05
User 1605519-May-03 4:05 
QuestionHow Can Get current dll 's directory path Pin
Boyren18-May-03 1:29
Boyren18-May-03 1:29 
AnswerRe: How Can Get current dll 's directory path Pin
Tim Smith18-May-03 1:50
Tim Smith18-May-03 1:50 
GeneralRe: How Can Get current dll 's directory path Pin
Boyren18-May-03 3:45
Boyren18-May-03 3:45 
AnswerRe: How Can Get current dll 's directory path Pin
Michael Dunn18-May-03 8:49
sitebuilderMichael Dunn18-May-03 8:49 
QuestionHow Can use CFileDialog in WTL Frameworks? Pin
Boyren18-May-03 1:22
Boyren18-May-03 1:22 
AnswerRe: How Can use CFileDialog in WTL Frameworks? Pin
Boyren18-May-03 1:40
Boyren18-May-03 1:40 
GeneralCstring/Atlstr.h Pin
DuFF17-May-03 1:36
DuFF17-May-03 1:36 
GeneralRe: Cstring/Atlstr.h Pin
Tim Smith17-May-03 4:07
Tim Smith17-May-03 4:07 
GeneralRe: Cstring/Atlstr.h Pin
Michael Dunn17-May-03 7:52
sitebuilderMichael Dunn17-May-03 7:52 
GeneralRe: Cstring/Atlstr.h Pin
DuFF17-May-03 8:57
DuFF17-May-03 8:57 
GeneralRe: Cstring/Atlstr.h Pin
Michael Dunn17-May-03 13:38
sitebuilderMichael Dunn17-May-03 13:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.