nsw1216
Member level 3
Hi all,
I would like ask that how can i set the precision of the input when reading from file?
For example, data from my input file are
My desired output are
However, i tried the code below
I got the output as below
May I know what is to codes or ways to get my desired output from reading data from a file ?
Your reply are most welcomed and appreciated.
Thank you in advance.
Best Regards.
I would like ask that how can i set the precision of the input when reading from file?
For example, data from my input file are
HTML:
-9.0000000e+000 -6.1000000e+001 3.7000000e+001 4.0000000e+000 1.1000000e+000 7.2300000e-012
-8.0000000e+000 -6.1000000e+001 3.7000000e+001 4.0000000e+000 1.1000000e+000 7.2300000e-012
My desired output are
HTML:
-9.00 -61.00 37.00 4.00 1.10 7.23e-012
-8.00 -61.00 37.00 4.00 1.10 7.23e-012
However, i tried the code below
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const int fac = 8485;
const int shift = 6;
double factory[fac][shift];
int z;
int main()
{
ifstream inFile("Testing.txt",ios::in);
inFile.precision(2);
inFile.setf(ios::fixed, ios::showpoint);
while (!inFile.eof())
{
for(int a=0; a<fac; a++)
{
for(int b=0; b<shift; b++)
{
inFile>>factory[a][b];
}
}
for(int a=0; a<fac; a++)
{
for(int b=0; b<shift; b++)
{
cout<<factory[a][b]<<" ";
}
cout<<endl;
}
}
inFile.close();
return 0;
}
I got the output as below
HTML:
-9 -61 37 4 1.1 7.23e-012
-8 -61 37 4 1.1 7.23e-012
May I know what is to codes or ways to get my desired output from reading data from a file ?
Your reply are most welcomed and appreciated.
Thank you in advance.
Best Regards.