Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. void make_neat(ifstream& messy_file, ofstream& neat_file,
  8.                int number_after_decimalpoint, int field_width);
  9. int main()
  10. {
  11.     ifstream fin;
  12.     ofstream fout;
  13.  
  14.     fin.open("rawdata.dat");
  15.     if(!fin.fail()) {
  16.         fout.open("neat.dat");
  17.         if(!fout.fail()) {
  18.             make_neat(fin, fout, 5, 12);
  19.             fin.close();
  20.             fout.close();
  21.             cout << "End of program. \n";
  22.         }
  23.         else {
  24.             cout << "404 File does not exist\n";
  25.         }
  26.     }
  27.     else {
  28.         cout << "404 File does not exist\n";
  29.     }
  30.     return 0;
  31. }
  32.  
  33. void make_neat(ifstream& messy_file, ofstream& neat_file,
  34.                int number_after_decimalpoint, int field_width)
  35. {
  36.     neat_file.setf(ios::fixed);
  37.     neat_file.setf(ios::showpoint);
  38.     neat_file.setf(ios::showpos);
  39.     neat_file.precision(number_after_decimalpoint);
  40.     cout.setf(ios::fixed);
  41.     cout.setf(ios::showpoint);
  42.     cout.setf(ios::showpos);
  43.     cout.precision(number_after_decimalpoint);
  44.  
  45.     double next;
  46.     while(messy_file >> next) {
  47.         cout << setw(field_width) << next << endl;
  48.         neat_file << setw(field_width) << next << endl;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement