Set the Field Width, setw() - C++ File Stream

C++ examples for File Stream:cout

Description

Set the Field Width, setw()

Demo Code

#include <iomanip>
#include <iostream>

int main(int argc, const char *argv[]) {
    int i = 12345;
    float f = 1.2345;

    for (int j = 10; j > 1; --j) {
        std::cout << "-----\nWidth: " << j << "\n-----\n"
                  << std::setw(j) << i << "\n"
                  << std::setw(j) << f << std::endl;
    }/*from  w  ww  . jav a2 s  .  c o m*/

    return 0;
}

Result


Related Tutorials