cout.setf(ios::left); // left justify output text
cout >> "This text is left-justified";
cout.unsetf(ios::left); // return to default (right justified)
That's because justification isn't just a flag, it's a field
with three different possible values. So you have to use the
two argument form of setf:
std::cout.setf( std::ios::left, std::ios::adjustfield ) ;
// ...
std::cout.setf( std::ios::right, std::ios::adjustfield ) ;
Note too that you normally want to restore the field when you're
through, not set it to some arbitrary default value. This is
best done by an RAII class, which saves the original value in
the constructor, and restores it in the destructor.
And of course, you don't usually use these commands except in
user defined manipulators. Which, if correctly designed, can
restore the original values at the end of the full expression.