Dear All,
I made data from the *.csv file as string read, and then made them write to *.txt file as string with precise values!
Now I want to convert the strings in text file with precise values to double. Here is the problem which is rounding them to integer numbers by atof(), istringstream() … etc.
I didn’t understand the reason why they couldn’t be converted to '‘double’'s with precise values !
PS : *.text and *.csv files are in the attachment.
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
void readfromCSV()
{
string serial, Sks,SKBs,SP500s,SP800s,SP900s,QE350s,QE400s,EBBs,IDBs;
double Sk,SKB,SP500,SP800,SP900,QE350,QE400,EBB,IDB;
double d;
char *pEnd;
ofstream out1;
out1.open("outtext.txt");
ofstream out;
out.open("HamamatsuInfo.txt",ios::out);
ifstream infile("Hamamatsu_R7600PMT_list.csv"); // for example
string line;
while (getline(infile, line)){
stringstream strstr(line);
string word;
double number;
while(getline(strstr,word,';')) { out<<setprecision(10)<<word<<'\t'; }
}
ifstream input;
input.open("HamamatsuInfo.txt",ios::in);
while(input>>serial>>Sks>>SKBs>>SP500s>>SP800s>>SP900s>>QE350s>>QE400s>>EBBs>>IDBs) {
// cout<<serial<<Sks<<SKBs<<SP500s<<SP800s<<SP900s<<QE350s<<QE400s<<EBBs<<IDBs<<endl;
IDB=atof(IDBs.c_str());
cout.precision(10);
cout<<IDBs<<"__"<<IDB<<endl;
/*
istringstream(Sks)>>Sk;
istringstream(SKBs)>>SKB;
istringstream(SP500s)>>SP500;
istringstream(SP800s)>>SP800;
istringstream(SP900s)>>SP900;
istringstream(QE350s)>>QE350;
istringstream(QE400s)>>QE400;
istringstream(EBBs)>>EBB;
istringstream(IDBs)>>IDB;
*/
}
}
Cheers,
Ersel
HamamatsuInfo.txt (82.5 KB)
Hamamatsu_R7600PMT_list.csv (82.5 KB)