Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- void make_neat(ifstream& messy_file, ofstream& neat_file,
- int number_after_decimalpoint, int field_width);
- int main()
- {
- ifstream fin;
- ofstream fout;
- fin.open("rawdata.dat");
- if(!fin.fail()) {
- fout.open("neat.dat");
- if(!fout.fail()) {
- make_neat(fin, fout, 5, 12);
- fin.close();
- fout.close();
- cout << "End of program. \n";
- }
- else {
- cout << "404 File does not exist\n";
- }
- }
- else {
- cout << "404 File does not exist\n";
- }
- return 0;
- }
- void make_neat(ifstream& messy_file, ofstream& neat_file,
- int number_after_decimalpoint, int field_width)
- {
- neat_file.setf(ios::fixed);
- neat_file.setf(ios::showpoint);
- neat_file.setf(ios::showpos);
- neat_file.precision(number_after_decimalpoint);
- cout.setf(ios::fixed);
- cout.setf(ios::showpoint);
- cout.setf(ios::showpos);
- cout.precision(number_after_decimalpoint);
- double next;
- while(messy_file >> next) {
- cout << setw(field_width) << next << endl;
- neat_file << setw(field_width) << next << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement