C++ examples for File Stream:cout
Setting the Width of a Field Using the setw Manipulator or Width Function
#include <iostream> #include <iomanip> #include <fstream> using namespace std; int main() //www.j a v a 2s .c om { ofstream sals("salaries.txt"); sals << setprecision(2); sals << fixed; sals << left; sals << setw(20) << "Name" << setw(10) << "Salary"; sals << endl; sals << "------------------- "; // 19 hyphens, one space sals << "----------" << endl; // 10 hyphens sals << setw(20) << "H"; sals << setw(10) << .82 << endl; sals << setw(20) << "B"; sals << setw(10) << 3.22 << endl; sals << setw(20) << "The is"; sals << setw(10) << 4.55 << endl; sals.close(); return 0; }