Hi,
my dad asked me two write a litlle program. Nothing special, except i have problems with string to float conversion...
Here is the code i wrote:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <stdlib.h>
#include <cstring>
#include <iomanip>
using namespace std;
//
main()
{
string sKBP, sE, sBP;
int iDS;
cout << "Name of the file:\n";
cin >> sBP;
sKBP += sBP + ".csv";
cout << "In which column data is?\n";
cin >> iDS;
const char *ccBP = sKBP.c_str ();
ifstream ifsB(ccBP /*"tete.csv"*/);
if(!ifsB)
cout << "bla bla..\n";
else
{
while (getline(ifsB, sE))
{
istringstream issE(sE);
string sL;
int iK=0;
while(getline(issE, sL, ';'))
{
iK++;
if (iK == iDS)
{
sL.erase(sL.begin() + sL.find(','));
/*char *cNL=new char[sL.size()+1];
cNL[sL.size()]=0;
memcpy(cNL, sL.c_str(), sL.size());
double test = strtod(cNL, NULL);*/
stringstream ssTF(sL);
float fTEST;
ssTF << sL;
ssTF >> fTEST;
//sL.push_back('\0');
//const char *ccL = sL.c_str();
cout << "String: " << setprecision(8) << /*atof(ccL)*/ fTEST /*sNL*/ << " length: " << sL.length() << "\n";
}
}
}
}
}
after conversion i get only one digit after floating point.. could someone help finding the problem ? works with setprecision - but thats only for cout.. but i need the precision in further calculations not in cout..