Line wrapping in ostream

A

Alex Dribin

Hi,

Are there ready solutions for auto-wrapping lines in ostream?

I am using ostream for output and want this output to be wrapped at some
position. Of course I can monitor stream pointer position and insert
end-of-lines periodically. Something better than that?

Alex
 
K

Karl Heinz Buchegger

Alex said:
Hi,

Are there ready solutions for auto-wrapping lines in ostream?

I am using ostream for output and want this output to be wrapped at some
position. Of course I can monitor stream pointer position and insert
end-of-lines periodically. Something better than that?

You want to equip the stream object with a custom stream buffer.
Search the newsgroup comp.lang.c++ for posts from Dietmar Kuehl.
He has posted examples of how to write stream buffer classes
in the past.
 
D

Dietmar Kuehl

Alex Dribin said:
Are there ready solutions for auto-wrapping lines in ostream?
Dunno.

I am using ostream for output and want this output to be wrapped at some
position. Of course I can monitor stream pointer position and insert
end-of-lines periodically. Something better than that?

Create a stream buffer whose buffer happens to be the maximum size of your
line. On buffer overflow you just search the buffer up to the first newline
and sent this portion, moving the remainder to the front of the buffer. If
there is no newline, you jsut sent the whole buffer followed by a newline
and emptying the buffer.

This stream buffer is probably a filtering stream buffer and would take
something like maybe 20 lines. Together with a few convenience classes you
will have something like 50 lines.
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top