Take the 2-minute tour ×

I would like to be able to channel two text streams to a single console window with a vertical split view. The ideal solution would be if I could simply write to two different std::ostream objects.

The reason I need it is to compare the output of two different versions of a program. I know there are simple workarounds like redirecting to file and using a diff program to view the differences. But that doesn't matter because this project is mostly just for fun.

I'm not sure however how to achieve this. Suppose that the left half has writtten 20 lines of output ahead of the right half. How do I move the cursor up to write the right half?

Can anyone give me some pointers on how to get started? Can this be done in pure C++ or do I need platform specific features?

share|improve this question
I think you would be better of saying "can the C++ language do this alone, or do I need a library of some kind". What exactly do you mean by a Platform? A version of a C++ Compiler? A library that ships with some particular compiler? –  Warren P Jan 28 '11 at 18:37
add comment

3 Answers

up vote 6 down vote accepted

This cannot be done using "pure c++" alone. You will need additional, potentially platform specific, libraries to implement the behavior you desire. For example, look at the ncurses library.

share|improve this answer
ncurses is a cross platform library, but as the question asks about if you can do this in C++ "only", perhaps the better way to say this is "you need a library of some kind, the C++ language itself doesn't provide console features, terminal emulation, and so on". –  Warren P Jan 28 '11 at 18:36
@Warren I've updated my answer –  Sam Miller Jan 28 '11 at 19:44
add comment

You can probably find some open source code in the olde terminal apps for text chat which did the same with a horizontal split.

Go back far enough and you will find usage of ansi escape sequences.

Writing something new ncurses is probably the way to go.

As an aside I reckon the diff/merge tool from tortoise is preatty good, from usage it really shows that simply putting code next to each other is probably not enough to make a useful eyeball comparison. You really get alot from the colourising and extra value add of the computer finding the differences for you.

share|improve this answer
add comment

Jlib may help.

A console library capable of colored input and output. Includes user definable menus, ASCII character windows, save/restore a screen worth of characters, 256 console color combinations, and a smart coloring.

share|improve this answer
add comment

Your Answer


