I've just started playing with file io.
My raw data file contains the following:
-52.387596 61.659180 -2.277227
-52.341648 61.521450 -2.243313
.....
and I want to output a file such
#PSI Format 1.0
#
# column [0] = "x"
# column [1] = "y"
# column [2] = "z"
# column [3] = "Energy"
# column [4] = "Id"
# type[3] = byte
-52.3876 61.6592 -2.27723 0 0
As you can see from numbers in my outputed file the numbers have been rounded.
Q - How do I get around this?
Heres my code
Code:
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main (int argv, char* arvc[]){
char *sourceFileName = "start.xyz";
char *destinationFileName = "finish.psi";
fstream finput;
fstream foutput;
finput.open(sourceFileName, ios::in);
foutput.open(destinationFileName, ios::out);
int index = 0;
string line;
double
x, y, z;
if (finput.is_open() && foutput.is_open()){
foutput << "#PSI Format 1.0" << endl;
foutput << "#" << endl;
foutput << "# column [0] = \"x\"" << endl;
foutput << "# column [1] = \"y\"" << endl;
foutput << "# column [2] = \"z\"" << endl;
foutput << "# column [3] = \"Energy\"" << endl;
foutput << "# column [4] = \"Id\"" << endl;
foutput << "# type[3] = byte" << endl;
foutput << "" << endl;
while (!finput.eof()){
finput >> x >> y >> z;
foutput << x << " " << y << " " << z << " " << 0 << " " << index << endl ;
index++;
}
foutput.close();
finput.close();
}else{
cout << "Error in opening eithe input or output files";
if (finput.is_open ()){
finput.close();
}
if (foutput.is_open()){
foutput.close();
}
}
cout << "Conversion undertaken";
cin.ignore();
cin.ignore ();
return 1;
}
Perhaps I'm missing something real silly. I tried to make x,y,z floats as well but this didnt work either :-(
Thanks for pointers.