473,378 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

data format

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::stringlines;
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::ofstream ofs( f.c_str() );
for (int i = 0; i < lines.size(); ++i)
ofs << lines[i] << 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;
}
}
}
************************************************** **************
Mar 5 '07 #1
3 2459
Gary Wessle wrote:
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
You've got this the wrong way round. In your program there are just
numbers (no formats), its only when you *write* out to a file that a
format is chosen.

Looking at your code (but not running it) it looks to me like you need
to change

std::stringstream sss;
sss << word << " " << val;
std::string tmp = sss.str();
lines.push_back( tmp );

to

std::stringstream sss;
sss << fixed << word << " " << val;
std::string tmp = sss.str();
lines.push_back( tmp );

fixed will prevent C++ from using the 'scientific' format you don't like.

john
Mar 5 '07 #2
John Harrison <jo*************@hotmail.comwrites:
Gary Wessle wrote:
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

You've got this the wrong way round. In your program there are just
numbers (no formats), its only when you *write* out to a file that a
format is chosen.

Looking at your code (but not running it) it looks to me like you need
to change

std::stringstream sss;
sss << word << " " << val;
std::string tmp = sss.str();
lines.push_back( tmp );

to

std::stringstream sss;
sss << fixed << word << " " << val;
std::string tmp = sss.str();
lines.push_back( tmp );

fixed will prevent C++ from using the 'scientific' format you don't like.

john
since the part of the code that prints out to the file is not what you
stated, did you mean?

ifs.close();
std::ofstream ofs( f.c_str() );
for (int i = 0; i < lines.size(); ++i)
ofs << lines[i] << std::endl;
ofs.close();

to

ifs.close();
std::ofstream ofs( f.c_str() );
for (int i = 0; i < lines.size(); ++i)
ofs << fixed << lines[i] << std::endl;
ofs.close();
Mar 5 '07 #3
Gary Wessle wrote:
John Harrison <jo*************@hotmail.comwrites:

>>Gary Wessle wrote:
>>>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

You've got this the wrong way round. In your program there are just
numbers (no formats), its only when you *write* out to a file that a
format is chosen.

Looking at your code (but not running it) it looks to me like you need
to change

std::stringstream sss;
sss << word << " " << val;
std::string tmp = sss.str();
lines.push_back( tmp );

to

std::stringstream sss;
sss << fixed << word << " " << val;
std::string tmp = sss.str();
lines.push_back( tmp );

fixed will prevent C++ from using the 'scientific' format you don't like.

john


since the part of the code that prints out to the file is not what you
stated, did you mean?

ifs.close();
std::ofstream ofs( f.c_str() );
for (int i = 0; i < lines.size(); ++i)
ofs << lines[i] << std::endl;
ofs.close();

to

ifs.close();
std::ofstream ofs( f.c_str() );
for (int i = 0; i < lines.size(); ++i)
ofs << fixed << lines[i] << std::endl;
ofs.close();

No I meant what I said. Your code (is it your code?) has a two stage
process to write out the data, first the data is written to a vector of
strings (the lines variable), then the vector of strings is written out
to a file. It when the numbers are written to the string vector that the
format is selected.

john
Mar 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3...
2
by: Trader | last post by:
Hi, I'm trying to use Mark Hammond's win32clipboard module to extract more complex data than just plain ASCII text from the Windows clipboard. For instance, when you select all the content on...
7
by: Bob | last post by:
Hi, I am trying to use BULK INSERT with format file. All of our data has few bytes of header in the data file which I would like to skip before doing BULK INSERT. Is it possible to write...
6
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
2
by: Adam Honek | last post by:
I have a form. It has serveral text boxes for user data entry. I could of course write code to check if each is empty before proceeding to save this data to a file. Is there any global way...
7
by: basyarie | last post by:
Dear VB mania, especially VB6 specialist I have a problem with my GPS. So far, I have a GPS-M1zz from Pioneer Navicom company. It has 2 type of data format, i.e. Pioneer Format and NMEA data...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
1
by: admin.offshoredataentry | last post by:
Data Entry Outsourcing provides time bound, cost effective and qualitative Data Entry also provides numeric data entry, textual data entry, image data entry, data format, data conversion and also...
7
ADezii
by: ADezii | last post by:
There are essentially three techniques for publishing Access Data on the Web. The first technique is static, and does not allow for the dynamic addition or modification to the data, There is no...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.