C++ examples for File Stream:cout
Set the field width and the fill character.
#include <iostream> using namespace std; int main()/*from w w w .java 2s .c o m*/ { // Use default width. cout << "Hello" << endl; // Set width to 10. cout.width(10); cout << "Hello" << endl; // Notice how width returns to default after an item is output. cout << "Hello" << endl; // Now set the width and the fill character. cout.width(10); cout.fill('*'); cout << "Hello" << endl; // Notice that fill character stays set. cout.width(12); cout << 123.45 << endl; // Now, pad the field width with spaces and // set the internal and showpos flags. cout.width(12); cout.fill(' '); cout.setf(ios::showpos | ios::internal); cout << 1234.1234 << endl; return 0; }