C++ ofstream setw()
set width
#include <iostream> #include <iomanip> #include <fstream> using namespace std; int main() /*www.j ava 2 s .co m*/ { 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; }