C++ ofstream fixed set decimal point

Description

C++ ofstream fixed set decimal point

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

using namespace std; 

int main() //w ww . ja  v  a 2 s  .  com
{ 
    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