G
Gary Wessle
Hi
I wrote 2 functions "included at the bottom" one inserts and one
reads data from a file, the data format is as here
****************
a 2
b -0.0336974
_time 1.17312e+09
****************
when I use the routine to read the value "_time", it reads as
1.17312e+09 but when it was entered it was 1173116800 and I want it
read back in the same correct format 1173106800.
how can I solve this with out screwing up the other data for a and b?
thanks
****************************************************************
// Set the value for the loopup string from file
void Orde_task::status(std::string lookup, double new_val)
{
std::string f = p_info->pair_status_dir + fxp;
std::ifstream ifs( f.c_str() );
std::vector<std::string> lines;
std::string line, word;
double val;
while( getline( ifs, line ) && line != "" )
{
std::stringstream ss( line) ;
ss >> word >> val;
if( word == lookup )
val = new_val;
std::stringstream sss;
sss << word << " " << val;
std::string tmp = sss.str();
lines.push_back( tmp );
}
ifs.close();
std:
fstream ofs( f.c_str() );
for (int i = 0; i < lines.size(); ++i)
ofs << lines << std::endl;
ofs.close();
}
// Get the value for the lookup string from file.
double Orde_task::status( std::string lookup)
{
std::string f = p_info->pair_status_dir + fxp;
std::ifstream ifs( f.c_str() );
std::string line, word;
double val;
while( getline( ifs, line ) && line != "" )
{
std::stringstream ss( line );
ss >> word >> val;
if( word == lookup )
{
ifs.close();
return val;
}
}
}
****************************************************************
I wrote 2 functions "included at the bottom" one inserts and one
reads data from a file, the data format is as here
****************
a 2
b -0.0336974
_time 1.17312e+09
****************
when I use the routine to read the value "_time", it reads as
1.17312e+09 but when it was entered it was 1173116800 and I want it
read back in the same correct format 1173106800.
how can I solve this with out screwing up the other data for a and b?
thanks
****************************************************************
// Set the value for the loopup string from file
void Orde_task::status(std::string lookup, double new_val)
{
std::string f = p_info->pair_status_dir + fxp;
std::ifstream ifs( f.c_str() );
std::vector<std::string> lines;
std::string line, word;
double val;
while( getline( ifs, line ) && line != "" )
{
std::stringstream ss( line) ;
ss >> word >> val;
if( word == lookup )
val = new_val;
std::stringstream sss;
sss << word << " " << val;
std::string tmp = sss.str();
lines.push_back( tmp );
}
ifs.close();
std:
for (int i = 0; i < lines.size(); ++i)
ofs << lines << std::endl;
ofs.close();
}
// Get the value for the lookup string from file.
double Orde_task::status( std::string lookup)
{
std::string f = p_info->pair_status_dir + fxp;
std::ifstream ifs( f.c_str() );
std::string line, word;
double val;
while( getline( ifs, line ) && line != "" )
{
std::stringstream ss( line );
ss >> word >> val;
if( word == lookup )
{
ifs.close();
return val;
}
}
}
****************************************************************