C++ ofstream setprecision() set precision

Description

C++ ofstream setprecision() set precision

#include <iostream> 
#include <iomanip> 
#include <fstream> 

using namespace std; 

int main() //from   w  ww .j a va  2s  . 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; 
}



PreviousNext

Related