Write a program that takes input from rawdata1.txt and writes a neat list of output to the screen
and to neat1.txt. Formatting instructions are used to create a neater layout: Numbers are written
one per line in a field width of 10. Each number is written with 3 digits after the decimal point.
Each number is written with a plus or minus sign. Write a function make_neat1 to format the
following text Uses “ 2345.45667 -0.0000456 34.9999 0.006788 -1 234
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
fstream file;
fstream file_write;
file.open("rawdata1.txt",ios::in); //Opening a file to perform read operation
file_write.open("neat1.txt",ios::out); //Opening a file to perform write operation
if (file.is_open()){
string tp;
while(getline(file, tp)){
cout << tp << "\n";
file_write<<tp<<setprecision(3)<<endl;
}
file.close();
file_write.close();
}
}
Comments
Leave a comment