// Fig. 21.24: fig21_24.cpp // Using the fill member function and the setfill // manipulator to change the padding character for // fields larger than the values being printed. #include using std::cout; using std::endl; #include using std::ios; using std::setw; using std::hex; using std::dec; using std::setfill; int main() { int x = 10000; cout << x << " printed as int right and left justified\n" << "and as hex with internal justification.\n" << "Using the default pad character (space):\n"; cout.setf( ios::showbase ); cout << setw( 10 ) << x << '\n'; cout.setf( ios::left, ios::adjustfield ); cout << setw( 10 ) << x << '\n'; cout.setf( ios::internal, ios::adjustfield ); cout << setw( 10 ) << hex << x; cout << "\n\nUsing various padding characters:\n"; cout.setf( ios::right, ios::adjustfield ); cout.fill( '*' ); cout << setw( 10 ) << dec << x << '\n'; cout.setf( ios::left, ios::adjustfield ); cout << setw( 10 ) << setfill( '%' ) << x << '\n'; cout.setf( ios::internal, ios::adjustfield ); cout << setw( 10 ) << setfill( '^' ) << hex << x << endl; return 0; } // end function main /************************************************************************** * (C) Copyright 1992-2004 by Deitel & Associates, Inc. and * * Pearson Education, Inc. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/