tags:

views:

381

answers:

2

I was trying std::cout.width(int) to see what it did, and it pushes the text right to fill a minimum width:

TH

becomes:

        TH

to fill a minimum width of 10. I am wondering if A) there is a way to reverse this, have a number of spaces put AFTER the text to fill a minimum width, and B) is there a way to create a maximum width AND a minimum width?

And on a lesser note, is it possible to create a class derived from cout or ostream?

+2  A: 

Width sets the "column" size for what you are printing next with cout.

std::cout << left << "Hello";

would print the above as "left" aligned in the column you made.

Different "types" are aligned to certain sides by default.

More info on this reference page.

Deinumite
+1  A: 

And on a lesser note, is it possible to create a class derived from cout or ostream?

One question at a time is a good idea, but you can't derive from cout because it is an instance, not a class. For details of deriving a new output stream type, read this book.

anon