C++ examples for File Stream:cout
Set the Field Width, setw()
#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; }